欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

查看linux服务器上jdk的安装路径方法

程序员文章站 2022-06-17 19:28:06
查看linux服务器上jdk的安装路径方法如何在一台linux服务器上查找jdk的安装路径呢? 有那些方法可以查找定位jdk的安装路径?是否有一些局限性呢? 下面总结了一下如何查找jdk安装路径的方法...

查看linux服务器上jdk的安装路径方法

如何在一台linux服务器上查找jdk的安装路径呢? 有那些方法可以查找定位jdk的安装路径?是否有一些局限性呢? 下面总结了一下如何查找jdk安装路径的方法.

1:echo $java_home

使用$java_home的话能定位jdk的安装路径的前提是配置了环境变量$java_home,否则如下所示,根本定位不到jdk的安装路径

[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 ~]# echo $java_home

查看linux服务器上jdk的安装路径方法

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]# 

查看linux服务器上jdk的安装路径方法

whereis java 也是如此,它本身不能定位到安装路径。可以通过上面例子去定位安装路径

查看linux服务器上jdk的安装路径方法

3: 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--

查看linux服务器上jdk的安装路径方法

linux查看jdk版本、卸载jdk

一:没有设置jdk环境变量

1、查看linux上jdk所在目录

[root@centos6 ~]# echo $java_home

得到jdk所在目录 /usr/java/jdk1.7.0_80

2、进入jdk所在目录

[root@centos6 ~]# cd /usr/java/jdk1.7.0_80

3、运行

[root@centos6 jdk1.7.0_80]# ./bin/java -version

结果如图:

查看linux服务器上jdk的安装路径方法

二:设置了环境变量

1、任意目录执行

[root@centos6 usr]# java -version

结果如图:

查看linux服务器上jdk的安装路径方法

三:卸载jdk

1. 确定jdk的版本:

[root@centos6 lib]# rpm -qa|grep jdk
[root@centos6 lib]# rpm -qa | grep gcj

可能的结果是:

jdk-1.7.0_80-fcs.x86_64
libgcj-4.4.7-3.el6.x86_64

2.然后卸载:

[root@centos6 lib]# rpm -e --nodeps libgcj-4.4.7-3.el6.x86_64
# 或者
[root@centos6 lib]# rpm -e --nodeps jdk-1.7.0_80-fcs.x86_64

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。