How to use java 1.7 instead of java 1.6 from console
We have this scenario.
We have installed JRE 1.6 and the developer issues the command
java -version |
and he gets java version “1.6 …”
But we have also installed JRE 1.7 and now our developer asks us to replace java 1.6 terminal command with java 1.7.
Let’s see how we can fix this issue in Ubuntu:
Issue the command
sudo update-alternatives --config java |
Ubuntu prompts you to select another alternative for java, and updates the symlink /etc/alternatives/java to point to the newly selected provider.
So, after selecting java 1.7 from the list, issue again the command
java -version |
to get java version “1.7.0 ….”
In general, you can install multiple java versions on a system, ie.
pluto:~ #ll /usr/java/
total 5
lrwxrwxrwx … 16 May 15 2008 default -> /usr/java/latest
drwxr-xr-x … 4096 May 4 2008 jdk1.4.2_28
drwxr-xr-x … 4096 Feb 4 2011 jdk1.6.0_23
drwxr-xr-x … 4096 Dec 15 2011 jdk1.7.0_11
lrwxrwxrwx … 21 Feb 4 2011 latest -> /usr/java/jdk1.7.0_11
Each user can use a different version of JAVA, depending on JAVA_HOME and PATH environment variable definitions (defined for example in ~/.bash_profile).
NOTE: same goes for Windows users, as %PATH% usually contains %JAVA_HOME%.