Dealing with multiple java versions is not a hard job. It is very simple but we need to use the same commands.
Suppose that you have multiple java versions install in your system. But some applications required java 7, some applications required java 8 and some other required another java version. Now it’s time to manage the java versions according to your application compatibility.
First, you need to list the all installed version of Java. The following command list all installed versions of Java with the default Java version.
update-java-alternatives --list
The results may vary, but this is an example of the output:
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-8-oracle 1081 /usr/lib/jvm/java-8-oracle
Identify your Java version, in this case, it is java-8-oracle. Then set it as the default with (replacing with the appropriate name from above listed Java versions)
sudo update-java-alternatives --jre --set
There is another way you can set a default version of Java. Use the following commands
sudo update-alternatives --config java
This command results:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Press enter to keep the current choice[*], or type selection number:
* is showing your current Java version. The above selections require the index of Java on your choice. For example, type 1 for Java 7 or press enter to keep same.
Congratulations, you have successfully updated your default Java version.
Thanks