Suppose you are working in a Linux system with multiple Java versions installed. So how to change the version of Java from this version to another version, this tutorial will guide you to do it!
For example, I’m using Ubuntu, and my Ubuntu is installing two versions of Java, namely:
- Java 6 Update 38
- Java 7 Update 95
By default, I’m using Java 7 Update 95, you can use the java -version command to test this.
1 2 3 4 |
khanh@ubuntu:~$ java -version java version "1.7.0_95" OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.15.04.1) OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode) |
Now, I want to use the Java 6 Update 38, I will use command update-alternatives on Ubuntu and do the following:
1 2 3 4 5 6 7 8 9 10 11 |
khanh@ubuntu:~$ sudo update-alternatives --config java [sudo] password for khanh: There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode Press enter to keep the current choice[*], or type selection number: |
In this step, if you change your mind, still want to use the current version of Java, press Enter, nothing changes.
I want to switch to Java version 6 Update 38 so I will choose 2 and press Enter. A message will be displayed informing you that the conversion was successful:
1 |
update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode |
Result:
1 2 3 4 |
khanh@ubuntu:~$ java -version java version "1.6.0_38" OpenJDK Runtime Environment (IcedTea6 1.13.10) (6b38-1.13.10-0ubuntu0.15.04.1) OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode) |