如何在⼀台Linux服务器上查找JDK的安装路径呢? 有那些⽅法可以查找定位JDK的安装路径?是否有⼀些局限性呢? 下⾯总结了⼀下如何查找JDK安装路径的⽅法.
1:echo $JAVA_HOME
使⽤$JAVA_HOME的话能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME,否则如下所⽰,根本定位不到JDK的安装路径[root@localhost ~]# java -versionjava version \"1.7.0_65\"
OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)[root@localhost ~]# echo $JAVA_HOME
2:which java
⾸先要申明⼀下which java是定位不到安装路径的。which java定位到的是java程序的执⾏路径。⽹上的资料都是⼈云亦云,完全不去思考。那么怎么定位到java的安装路径呢?下⾯我们来看看例⼦吧,如下所⽰:
[root@localhost ~]# java -version
java version \"1.7.0_65\"
OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@localhost ~]# which java
/usr/bin/java
[root@localhost ~]# ls -lrt /usr/bin/java
lrwxrwxrwx. 1 root root 22 Aug 17 15:12 /usr/bin/java -> /etc/alternatives/java
[root@localhost ~]# ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 46 Aug 17 15:12 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
[root@localhost ~]#
[root@localhost ~]# cd /usr/lib/jvm
[root@localhost jvm]# ls
java-1.6.0-openjdk-1.6.0.0.x86_64 java-1.7.0-openjdk-1.7.0.65.x86_64 jre jre-1.6.0 jre-1.6.0-openjdk.x86_64 jre-1.7.0 jre-1.7.0-openjdk.x86_64 jre-openjdk
[root@localhost jvm]#
whereis java 也是如此,它本⾝不能定位到安装路径。可以通过上⾯例⼦去定位安装路径
因篇幅问题不能全部显示,请点此查看更多更全内容