How to change the Java version/enviroment in Ubuntu

If you have installed multiple Java-Versions and you want to configure your system to use one of them as the default, there is a really simple command to achieve that goal:

1) Check Java version

$ java -version
  • The output should look similar to something like this:
    java version "1.7.0_147-icedtea"
    OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-0ubuntu0.11.10.1)
    OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

    As you can see my systems default is set to java-7-openjdk (1.7.0_147-icedtea).

2) Switch between installed Java versions

$ sudo update-alternatives --config java
  • Again the output should look similar to something like this:
    There are two possible choices for the alternative java.
    Selection   Path                                     Priority State
    0        /usr/lib/jvm/java-6-openjdk/jre/bin/java        1061 auto   mod
    1        /usr/lib/jvm/java-6-openjdk/jre/bin/java        1061 manuel mod
    * 2      /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java  1051 manuel mod
    Press return to keep your current choice[*] or type a selection number:_

    The [*] indicates the java version that’s currently the systems default (java -version already told us this). Now you could change your systems default java environment from e.g. java-7-openjdk to java-6-openjdk by typing 1 and pressing return. If you want to verify the results of your actions run the command from 1) again.

About M0nk3ym0nk3y

M0nk3ym0nk3y is one of the three LinuxM0nk3ys from Linux M0nk3ys @ WordPress Linux M0nk3ys @ YouTube Linux M0nk3ys @ Twitter

Posted on August 25, 2012, in Configure, Install and tagged , , , , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: