Java:未找到 CentOS Linux 版本 7.3.1611 的命令

Java:未找到 CentOS Linux 版本 7.3.1611 的命令

我已经按照另一个类似的 CentOS Linux 版本 7.3.1611 上的以下步骤安装了 java,并且运行良好。在这台机器上我运行了如下相同的步骤

1. wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz"
2. tar -xvzf jdk-8u121-linux-x64.tar.gz
3. alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_121/java 2
4. alternatives --config java
5. alternatives --install /usr/bin/javac javac /usr/local/jdk1.8.0_121/bin/javac 2
6. alternatives --set javac /usr/local/jdk1.8.0_121/bin/javac
7. export PATH=$PATH:/usr/local/jdk1.8.0_121/bin:/usr/local/jdk1.8.0_121/jre/bin

因此,每次当我再次运行此步骤时, java -version 就会起作用。一段时间后,它变成找不到相同的命令。

我的错误是什么?

答案1

您问题的第 3 行有一个拼写错误。在替代命令中省略“/usr/local/jdk1.8.0_121/java”中的“/bin/”。应该是“/usr/local/jdk1.8.0_121/bin/java”。

alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_121/bin/java 180121

额外信息:当我以这种方式安装Java时,我还在alternatives命令中使一些辅助程序成为从属程序。对于优先级,我根据 Java 版本号创建了一个字符串。您只需使用单行命令即可完成,但我会使用类似于以下内容的命令:

alternatives --install /usr/bin/java java \
   /usr/local/jdk1.8.0_121/bin/java 180121 \
   --slave /usr/bin/jar jar /usr/local/jdk1.8.0_121/bin/jar \
   --slave /usr/bin/jarsigner jarsigner /usr/local/jdk1.8.0_121/bin/jarsigner \
   --slave /usr/bin/javac javac /usr/local/jdk1.8.0_121/bin/javac \
   --slave /usr/bin/javadoc javadoc /usr/local/jdk1.8.0_121/bin/javadoc \
   --slave /usr/bin/javah javah /usr/local/jdk1.8.0_121/bin/javah \
   --slave /usr/bin/javap javap /usr/local/jdk1.8.0_121/bin/javap \
   --slave /usr/bin/javaws javaws /usr/local/jdk1.8.0_121/bin/javaws \
   --slave /usr/bin/jconsole jconsole /usr/local/jdk1.8.0_121/bin/jconsole \
   --slave /usr/bin/jcontrol jcontrol /usr/local/jdk1.8.0_121/bin/jcontrol \
   --slave /usr/bin/jdb jdb /usr/local/jdk1.8.0_121/bin/jdb \
   --slave /usr/bin/jhat jhat /usr/local/jdk1.8.0_121/bin/jhat \
   --slave /usr/bin/jinfo jinfo /usr/local/jdk1.8.0_121/bin/jinfo \
   --slave /usr/bin/jmap jmap /usr/local/jdk1.8.0_121/bin/jmap \
   --slave /usr/bin/jps jps /usr/local/jdk1.8.0_121/bin/jps \
   --slave /usr/bin/jrunscript jrunscript /usr/local/jdk1.8.0_121/bin/jrunscript \
   --slave /usr/bin/jsadebugd jsadebugd /usr/local/jdk1.8.0_121/bin/jsadebugd \
   --slave /usr/bin/jstack jstack /usr/local/jdk1.8.0_121/bin/jstack \
   --slave /usr/bin/jstat jstat /usr/local/jdk1.8.0_121/bin/jstat \
   --slave /usr/bin/jstatd jstatd /usr/local/jdk1.8.0_121/bin/jstatd \
   --slave /usr/bin/jvisualvm jvisualvm /usr/local/jdk1.8.0_121/bin/jvisualvm

相关内容