Centos – JAVA_HOME versus java -version

centoscentos6centos7java

I've two JDK's on my CentOS machine, 1.7 and 1.8.

When I set my JAVA_HOME to 1.7 the java -version command still shows 1.8

What's this? And how to fix?

Best Answer

It depends on how you run java. If you run java -version without specifying any path, the first java executable found in $PATH environment variable is used. This has nothing to do with JAVA_HOME var.

If you want to change the java executable you are using based on changing the JAVA_HOME var, you can run it:

$JAVA_HOME/bin/java -version