2

I have installed JDK 1.8 on my ubuntu 16.04, for some kind of work I had to install JDK 1.7.I installed it without did anything to my older version and changed the $JAVA_HOME to point the newly installed location.

echo $JAVA_HOME works fine , showing newly installed version which is 1.7

but when I do $ java -version it shows earlier installed version which is 1.8.

Why does this happen? How to resolve it.

I need 1.7 to work with it further.

If I went wrong in somewhere please correct me,I need good explanation regarding this.

Thank you. here is my terminal

terminal

3
  • 1
    You need to set the PATH. JAVA_HOME is irrelevant. Commented Jul 1, 2016 at 6:35
  • I have put these lines in bashrc #JAVA HOME directory setup export JAVA_HOME=/usr/lib/java/jdk1.7.0_79 export PATH="$PATH:$JAVA_HOME/bin" Commented Jul 1, 2016 at 6:38
  • in case you installed your java's from the webupd8 ppa also installed the oracle-java7-set-default package. Commented Jul 1, 2016 at 6:44

1 Answer 1

5

Try to run following command in terminal:

$ sudo update-alternatives --config java

It shows installed alternatives for java command. You can choose which one you will use by default further on.

Sign up to request clarification or add additional context in comments.

2 Comments

could you be able explain this further to me?
update-alternatives updates the links in /etc/alternatives to point the command to the actual program to run. askubuntu.com/questions/233190/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.