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

MT0
  • 143,790
  • 11
  • 59
  • 117
  • 1
    You need to set the PATH. JAVA_HOME is irrelevant. – JB Nizet Jul 01 '16 at 06: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" –  Jul 01 '16 at 06:38
  • in case you installed your java's from the [webupd8 ppa](http://stackoverflow.com/a/16263651/995891) also installed the `oracle-java7-set-default` package. – zapl Jul 01 '16 at 06:44

1 Answers1

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.

Holger
  • 285,553
  • 42
  • 434
  • 765
Oleg Kurbatov
  • 1,376
  • 1
  • 19
  • 32
  • could you be able explain this further to me? –  Jul 01 '16 at 06:44
  • `update-alternatives` updates the links in /etc/alternatives to point the command to the actual program to run. http://askubuntu.com/questions/233190/what-exactly-does-update-alternatives-do – Oleg Kurbatov Jul 01 '16 at 06:47