如何在 CentOS 中获取 java 路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33104982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:19:54  来源:igfitidea点击:

How to get java path in CentOS?

javapathcentos7

提问by Naou

I need to configure my Jenkins Server and I need to add Java path to Jenkins configuration.

我需要配置我的 Jenkins 服务器,我需要向 Jenkins 配置添加 Java 路径。

yum install java-1.8.0-openjdk

yum install java-1.8.0-openjdk

However I'm new to lunix command, any suggestion please?

但是我是 lunix 命令的新手,请问有什么建议吗?

I dont know where yum install it!

我不知道 yum 安装在哪里!

See the validated answer!

查看经过验证的答案!

采纳答案by Naou

Here are the solution

这是解决方案

# cd /opt/jdk1.7.0_79/
# alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 2
# alternatives --config java
# alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 2
# alternatives --set jar /opt/jdk1.7.0_79/bin/jar
# alternatives --set javac /opt/jdk1.7.0_79/bin/javac 
# java -version

java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

# export JAVA_HOME=/opt/jdk1.7.0_79
# export PATH=$PATH:/opt/jdk1.7.0_79/bin

Thanks to tecadmin

感谢技术管理员

回答by Henni

Try echo $JAVA_HOME or look in vi ~/.bash_profile

尝试 echo $JAVA_HOME 或查看 vi ~/.bash_profile

回答by thomas.mc.work

They usually reside in /usr/lib/jvm. You can list them via ll /usr/lib/jvm. The value you need to enter in the field JAVA_HOMEin jenkins is /usr/lib/jvm/java-1.8.0-openjdk.

他们通常居住在/usr/lib/jvm. 您可以通过 列出它们ll /usr/lib/jvm。您需要JAVA_HOME在 jenkins的字段中输入的值为/usr/lib/jvm/java-1.8.0-openjdk.

Update

更新

when I look at '/usr/lib/jvm' I get ...

当我查看'/usr/lib/jvm'时,我得到...

What you see there is a list of symbolic links pointing to a similar target located in /etc/alternatives. In the end they all point to the same target. The difference is only the name which allows you to choose how explicit your choice if the target version shall be.

您看到的是一个符号链接列表,指向位于/etc/alternatives. 最后,它们都指向同一个目标。区别仅在于名称允许您选择目标版本是否明确。

(Because java-1.8.0-openjdkis missing: Maybe you also need to install the package java-1.8.0-openjdk-devel.)

(因为java-1.8.0-openjdk缺少:也许你还需要安装包java-1.8.0-openjdk-devel。)

回答by Pravin

try this if java command works

如果 java 命令有效,请尝试此操作

readlink -f $(which java)