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 ….”