-1

please see my command output below:

steven81@LinuxVMzhexin:~$ echo $JAVA_HOME
/usr/local/jdk-10.0.1
steven81@LinuxVMzhexin:~$ cd /usr/local/jdk-10.0.1/
steven81@LinuxVMzhexin:/usr/local/jdk-10.0.1$ ls -l
total 32
drwxr-xr-x   2 root root 4096 Jun 12 23:52 bin
drwxr-xr-x   4 root root 4096 Jun 12 23:52 conf
drwxr-xr-x   3 root root 4096 Jun 12 23:52 include
drwxr-xr-x   2 root root 4096 Jun 12 23:52 jmods
drwxr-xr-x 101 root root 4096 Jun 12 23:52 legal
drwxr-xr-x  12 root root 4096 Jun 12 23:52 lib
-r--r--r--   1 root root  158 Jun 12 23:52 README.html
-rw-r--r--   1 root root 1656 Jun 12 23:52 release
steven81@LinuxVMzhexin:/usr/local/jdk-10.0.1$ ./bin/java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
steven81@LinuxVMzhexin:/usr/local/jdk-10.0.1$ cd ~
steven81@LinuxVMzhexin:~$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)    

From the output the JAVA_HOME has been set to /usr/local/jdk-10.0.1, but why I use this command:

java -version    

I always get the output like this:

openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode) 

how to fix this issue?

user2575502
  • 703
  • 12
  • 28
  • Possible duplicate of [JAVA_HOME directory in Linux](https://stackoverflow.com/q/1117398/608639), [How to set JAVA_HOME in Linux for all users](https://stackoverflow.com/q/24641536/608639), [JAVA_HOME and PATH are set but java -version still shows the old one](https://stackoverflow.com/q/14119983/608639), [What is JAVA\_HOME? How does the JVM find the javac path stored in JAVA\_HOME?](https://stackoverflow.com/q/2025290/608639), etc – jww Jun 13 '18 at 01:17

1 Answers1

0

Other than JAVA_HOME you might need JAVA_PATH as well. Here what works on my system:

Add following to your ~/.profile file:

PATH="/usr/local/jdk-10.0.1/bin:$PATH"
export JAVA_PATH="/usr/local/jdk-10.0.1"
export JAVA_HOME="/usr/local/jdk-10.0.1"

It would be much better if you rename your /usr/local/jdk-10.0.1 to something like /usr/local/jdk10.

From where the JAVA_PATH came?

I don't remember well but this has problem with some previously installed openjdk. For most of user's JAVA_PATH is not required but all I know is, it helped me solve my problem.

miken32
  • 42,008
  • 16
  • 111
  • 154
Avezan
  • 673
  • 4
  • 9