Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different version of java displayed in $JAVA_HOME and java -version in linux

I am using Cent-OS.

When I execute "java -version", it displays: java version "1.7.0_45"

When i execute "echo $JAVA_HOME", it displays /usr/java/jdk1.8.0_51

I set JAVA_HOME in ~/.bashrc and sourced it. I also tried setting in /etc/profile and sourced it as well. In profiles, I am setting java home as:

JAVA_HOME=/usr/java/jdk1.8.0_51

export PATH=$PATH:$JAVA_HOME/bin

Please tell me how to set java version to 1.8 only.

like image 274
technicalworm Avatar asked Dec 08 '25 18:12

technicalworm


1 Answers

I believe 1.7.0_45 is set in your path already, and in order to use 1.8.0_51, export the path as follows,

export PATH=$JAVA_HOME/bin:$PATH 

This will add new JAVA path in front of the existing java path. The issue in your export is the new java path is added after the existing path. Hope this helps.

like image 177
Sathish Avatar answered Dec 11 '25 09:12

Sathish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!