启动 Jenkins bash: /usr/bin/java: No such file or directory

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20031475/
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-12 22:29:58  来源:igfitidea点击:

Starting Jenkins bash: /usr/bin/java: No such file or directory

javabashjenkinscentoscentos6

提问by Jonathan Airey

I have a CentOS server and I'm trying to run jenkins as a service with:

我有一个 CentOS 服务器,我正在尝试将 jenkins 作为服务运行:

service jenkins start

I am running as rootuser and I'm getting this response:

我以root用户身份运行,并收到以下响应:

Starting Jenkins bash: /usr/bin/java: No such file or directory
                                                       [FAILED]

I have echo'ed a few things to the command line:

echo在命令行中做了一些事情:

[root@xyz opt]# echo $JAVA_HOME
/opt/jdk
[root@xyz opt]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/jdk/bin:/opt/grails/bin
[root@xyz opt]# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
[root@xyz opt]# which java
/opt/jdk/bin/java

I cannot see any java configuration in any jenkins files. Any ideas?

我在任何 jenkins 文件中都看不到任何 java 配置。有任何想法吗?

采纳答案by saulotoledo

Try fix it by using:

尝试使用以下方法修复它:

ln -s /opt/jdk/bin/java /usr/bin/java

The script file who service utility is using is probably /etc/init.d/jenkins You could edit this file too...

服务实用程序正在使用的脚本文件可能是 /etc/init.d/jenkins 您也可以编辑此文件...

回答by Zeeshan

Jenkins needs java to start and in your case in /usr/bin/directory javais not available

Jenkins 需要 java 才能启动,在您的情况下,/usr/bin/目录java不可用

If you go to /etc/init.d/and open jenkinsfile you will find:

如果你去/etc/init.d/打开jenkins文件,你会发现:

candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"

These are the paths where jenkins looks for java, and in your case java was not present in any of the above paths.

这些是 jenkins 查找 java 的路径,在您的情况下,java 不存在于上述任何路径中。

So look for the path where you are having java and add that path in the above jenkins file.

因此,查找您拥有 java 的路径并将该路径添加到上面的 jenkins 文件中。

Since you are having java in /opt/jdk/bin, then add this in jenkinsfile:

既然你有 java in /opt/jdk/bin,那么在jenkins文件中添加这个:

    candidates="
/opt/jdk/bin/java <----Add here 
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
"