使用$JAVA_HOME的话能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME,否则如下所示,根本定位不到JDK的安装路径。
正确的方式是通过 which java:
[[email protected] conf]$ java -version openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) [[email protected] conf]$ echo $JAVA_HOME [[email protected] conf]$ echo $PATH /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/app/tt/.local/bin:/app/tt/bin [[email protected] conf]$ whereis java java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz [[email protected] conf]$ which java /usr/bin/java [[email protected] conf]$ cd /usr/bin/java -bash: cd: /usr/bin/java: Not a directory [[email protected] conf]$ ls -lrt /usr/bin/java lrwxrwxrwx. 1 root root 22 Oct 18 11:19 /usr/bin/java -> /etc/alternatives/java [[email protected] conf]$ ls -lrt /etc/alternatives/java lrwxrwxrwx. 1 root root 70 Oct 18 11:19 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java [[email protected] conf]$ cd /usr/lib/jvm [[email protected] jvm]$ ls java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64 jre-1.7.0 jre-1.8.0 jre-openjdk java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64 jre-1.7.0-openjdk jre-1.8.0-openjdk jre jre-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64 jre-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64 [[email protected] jvm]$
时间: 2024-10-13 17:23:22