前言
有的时候我们安装了jdk,配置好了环境变量,时间一长却忘了安装路径在哪,这是让人很头疼的一件事,也有时候我们安装了jdk,一时忘记刚刚安装的路径在哪了。下面我将就这两种情况分别来说明下该怎么去查看对应的安装路径。
1.配置JAVA环境变量
编辑/etc/profilewen文件,在文件末尾添加
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
然后运行source
/etc/profile使配置生效
source /etc/profile
查看JAVA_HOME环境变量
han@ubuntu:/etc$ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
2.查看jdk的安装路径
第一种情况:已经安装好了jdk,也配置了环境变量,这种情况下,查看jdk路径是很容易的。
-
在window环境下,我们先执行java -version 指令查看是否已经配置过java了,如果查到java版本则证明已经安装配置过了,那么我们就可以进行下一步操作。
-
在配置过jdk的情况下,执行java -verbose指令,在打印出的文本最后两行可以看到jdk的安装路径,如下图。
-
在linux环境下,其实执行的指令与window下是一致的,如下图。
上面这种情况一般很容易就能发现jdk路径。
第二种情况:是未配置jdk的环境变量该怎么找到他的安装路径,这种情况下就不能执行java的指令了。
-
window下我们找寻起来可能要麻烦些,在不同盘下输入DIR /S jre 来进行搜索,或者你不用jre,用其他jdk固有的文件来做搜索条件也可以。如下图,也是可以找到jdk的路径的。
-
在linux的环境下,操作就不一样了,你需要执行 find / -name jre 来进行搜索,就可以直接找到jdk的路径了。如下图所示。
好了,以上就是几种不同情况,在window和linux下该如何看jdk的路径的解决方法了,另外,值得一说的是,后两种方法不仅可以找到jdk,还可以找到其他软件的安装路径。
3.其它查找jdk安装路径的方法
3.1 which java
首先要申明一下which java是定位不到安装路径的。which java定位到的是java程序的执行路径。网上的资料都是人云亦云,完全不去思考。那么怎么定位到java的安装路径呢?下面我们来看看例子吧,如下所示:
[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 ~]# which java/usr/bin/java[root@localhost ~]# ls -lrt /usr/bin/javalrwxrwxrwx. 1 root root 22 Aug 17 15:12 /usr/bin/java -> /etc/alternatives/java[root@localhost ~]# ls -lrt /etc/alternatives/javalrwxrwxrwx. 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]# lsjava-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 也是如此,它本身不能定位到安装路径。可以通过上面例子去定位安装路径
3.2 rpm -ql packagename
如果JDK是源码安装的话,那么这个方法也是行不通的。也就是说rpm –ql packagename也是有一定局限性的。
[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 ~]# rpm -qa | grep java
tzdata-java-2014g-1.el6.noarch
java-1.6.0-openjdk-1.6.0.0-11.1.13.4.el6.x86_64
java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64
[root@localhost ~]# rpm -ql java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64 | more
/etc/.java
/etc/.java/.systemPrefs
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jaas-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jaas-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jaas.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jce-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jce-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jce.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jdbc-stdext-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jdbc-stdext-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jdbc-stdext-3.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jdbc-stdext.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-cos-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-cos-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-cos.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-ldap-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-ldap-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-ldap.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-rmi-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-rmi-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi-rmi.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jndi.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jsse-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jsse-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/jsse.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/sasl-1.7.0.65.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/sasl-1.7.0.jar
/usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.65.x86_64/sasl.jar
/usr/lib/jvm-exports/jre-1.7.0-openjdk.x86_64
/usr/lib/jvm-private/java-1.7.0-openjdk.x86_64
/usr/lib/jvm-private/java-1.7.0-openjdk.x86_64/jce
/usr/lib/jvm-private/java-1.7.0-openjdk.x86_64/jce/vanilla
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/ASSEMBLY_EXCEPTION
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/LICENSE
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/THIRD_PARTY_README
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/keytool
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/orbd
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/pack200
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/policytool
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/rmid
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65.x86_64/jre/bin/rmiregistry
--More--