请参阅下面的命令输出:
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)
从输出中将JAVA_HOME设置为/usr/local/jdk-10.0.1,但为什么我使用此命令:
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)
如何解决此问题?
答案 0 :(得分:0)
除了JAVA_HOME,您可能还需要JAVA_PATH。这对我的系统有用:
将以下内容添加到~/.profile
文件中:
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"
如果您将/usr/local/jdk-10.0.1
重命名为/usr/local/jdk10
,那会好得多。
关于投票的更新:
JAVA_PATH
来自哪里?
我不记得了,但这与先前安装的openjdk
有问题。对于大多数用户JAVA_PATH
不是必需的,但我知道的是,它帮助我解决了我的问题。