linux 查看java的安装路径

2022-03-09 00:00:00 路径 查看 安装

获取java安装路径前要判断是否已经安装成功java

执行命令:

java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32	  use a 32-bit data model if available
    -d64	  use a 64-bit data model if available
    -server	  to select the "server" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
    .......

在查看java版本:

java -version
[root@localhost Desktop]# 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)

———————————-分割线————————————–

如果以上2步都没问题就可以查询安装路径了

  1. 如果在/etc/profile文件中配置了JAVA_HOME则可以直接获取:
echo $JAVA_HOME
[root@localhost local]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
  1. 如果以上方法无法查询到,使用如下:
[root@localhost local]# which java
/usr/bin/java

[root@localhost local]# ls -lrt /usr/bin/java
lrwxrwxrwx. 1 root root 22 Mar  7 19:12 /usr/bin/java -> /etc/alternatives/java

[root@localhost local]# ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 70 Mar  7 19:12 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
  1. 然后编辑/etc/profile文件,在文件末尾添加
vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  1. 保存命令设置
source /etc/profile
  1. 在执行查看命令:
[root@localhost local]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
    原文作者:威威dett
    原文地址: https://blog.csdn.net/u013626215/article/details/88964331
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。

相关文章