Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Java versions on CentOS

I have installed JAVA 1.7_80 in my centOS machine, but when I check the Java version it shows 1.7_09.

I ran the ./java -version in the installation directory which correctly shows 1.7_80, but the global java -version is 1.7_09.

Please refer the link for image - https://scontent.xx.fbcdn.net/hphotos-xft1/v/t1.0-9/11667333_914348581933741_3461411661734554342_n.jpg?oh=e8d3037e2f6492757b0f786bd0ae8f77&oe=56318F12

Does someone know what could be the cause or how to fix this?

like image 293
Anant Sachdeva Avatar asked Sep 01 '25 22:09

Anant Sachdeva


1 Answers

There's default OpenJDK in CentOS,


OPTION A

You have to install JDK with alternatives.

# cd /opt/jdk1.8.0_101/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_101/bin/java 2
# alternatives --config java

THE OUTPUT ==>

There are 2 programs which provide 'java'.

Selection    Command
-----------------------------------------------
  1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.el7_2.x86_64/jre/bin/java
+ 2           /opt/jdk1.8.0_101/bin/java

Enter to keep the current selection[+], or type selection number: 

Select the version you want from this list.


OR : OPTION B

#ls -l /usr/bin/java

OUTPUT : . 1 root root 22 සැප් 9 02:09 /usr/bin/java -> /etc/alternatives/java

then # ls -l /etc/alternatives/java

OUTPUT : . 1 root root 26 සැප් 9 02:09 /etc/alternatives/java -> /opt/jdk1.8.0_101/bin/java

#unlink /etc/alternatives/java 
#ln -s <new location> /etc/alternatives/java

(ln -s <original file> <link to file> )

But I prefer the option A.

like image 138
Thara Perera Avatar answered Sep 03 '25 13:09

Thara Perera