我在 CentOS 上安装了 Open JDK 1.7;我安装了 Oracle 的 Java rpm;Oracle Java 似乎不存在

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

I had Open JDK 1.7 on CentOS; I installed Oracle's Java rpm; Oracle Java doesn't seem to exist

javalinuxoraclecentosrpm

提问by dataquerent

I started off with CentOS and OpenJDK 1.7

我从 CentOS 和 OpenJDK 1.7 开始

# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

In order to run a specific application, I want to use Oracle's Java 1.6, provided from an RPM.

为了运行特定的应用程序,我想使用 RPM 提供的 Oracle 的 Java 1.6。

I copied the Oracle binary to a specific new directory:

我将 Oracle 二进制文件复制到特定的新目录:

# pwd
/oracleJava/jdk-6u45-linux-x64-rpm

I extracted the binary and it gave me the following files:

我提取了二进制文件,它给了我以下文件:

# ls
jdk-6u45-linux-amd64.rpm               
sun-javadb-core-10.6.2-1.1.i386.rpm  sun-javadb-javadoc-10.6.2-1.1.i386.rpm
sun-javadb-client-10.6.2-1.1.i386.rpm  sun-javadb-demo-10.6.2-1.1.i386.rpm
sun-javadb-common-10.6.2-1.1.i386.rpm  sun-javadb-docs-10.6.2-1.1.i386.rpm

I installed the RPM and the rpm utility believes that it installed properly: rpm -q jdk jdk-1.6.0_45-fcs.x86_64

我安装了 RPM 并且 rpm 实用程序认为它安装正确: rpm -q jdk jdk-1.6.0_45-fcs.x86_64

# rpm -Uvh ./*.rpm
Preparing...                ########################################### [100%]
    package jdk-2000:1.6.0_45-fcs.x86_64 is already installed
# rpm -Uvh sun-javadb-*.rpm
 [I omit the feedback because it generates a formatting error]
#

However, the Java version just shows 1.7 # java -version java version "1.7.0_25" OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64) OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

但是,Java 版本只显示 1.7 # java -version java version "1.7.0_25" OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64) OpenJDK 64-Bit Server VM(build 23.7-b01,混合模式)

In other words, I was expecting the Oracle files to give me some new /java directory somewhere, with a new java executable that would return a different answer for "java -version"

换句话说,我期待 Oracle 文件在某处为我提供一些新的 /java 目录,并带有一个新的 java 可执行文件,该可执行文件将为“java -version”返回不同的答案

I need that new directory so that I can set JAVA_HOME and use the 1.6 version of Java.

我需要那个新目录,以便我可以设置 JAVA_HOME 并使用 1.6 版本的 Java。

Helpful suggestions would be greatly appreciated. Thanks in advance.

有用的建议将不胜感激。提前致谢。

采纳答案by Stephen C

The problem is that Oracle's RPMs are (wilfully IMO!) ignorant of the "alternatives" system.

问题是 Oracle 的 RPM(故意 IMO!)对“替代品”系统一无所知。

Instead, they install stuff in a non-standard place (/usr/java) and then expect the user / system administrator to mess with the PATH variable ... by hand.

相反,他们将东西安装在一个非标准的地方 (/usr/java),然后期望用户/系统管理员手动修改 PATH 变量……。

It is a nuisance!

这是一个麻烦!



So what has probably happened in your case is that your JDK / JRE has been installed in a subdirectory of /usr/java ... but since you haven't added the relevant binsubdirectory to the front of your PATHyou are still picking up the OpenJDK tools via the javacommand name.

因此,在您的情况下可能发生的情况是您的 JDK/JRE 已安装在 /usr/java 的子目录中...但是由于您尚未将相关bin子目录添加到您的前面,因此您PATH仍在选择 OpenJDK工具通过java命令名称。



You can fix this after the fact by using "alternatives" to configure and then select the Oracle commands. But it is messy, especially if you want the JDK tools as well. (There are a lot of them!)

您可以事后通过使用“替代方案”来配置然后选择 Oracle 命令来解决此问题。但这很麻烦,尤其是如果您还需要 JDK 工具时。(有很多!)

If you use Chef, another approach is to use the "java" cookbook to do the installation.

如果您使用 Chef,另一种方法是使用“java”说明书进行安装。

回答by learningloop

Run the following command to see if your JVM is getting listed.

sudo update-alternatives --config java

运行以下命令以查看您的 JVM 是否被列出。

sudo update-alternatives --config java

If your JVM gets listed select it.

如果您的 JVM 被列出,请选择它。

回答by Keerthivasan

Please check that whether your JAVA_HOME points to JDK 6 using echo $JAVA_HOME. In order change your JAVA_VERSIONto Java 6, you need to point to the Java development KIT 6. You also need to add the bin directory to the $PATHvariable. Please ensure that JDK6 bin directory comes in the $PATH prior to other JDK bin,if any. You can check the version of your Java in the environment by command java -version.The other answer by learningloop is very perfect to switch between different Java configurations

请使用 echo 检查您的 JAVA_HOME 是否指向 JDK 6 $JAVA_HOME。为了将您更改JAVA_VERSION为 Java 6,您需要指向 Java 开发 KIT 6。您还需要将 bin 目录添加到$PATH变量中。请确保 JDK6 bin 目录在其他 JDK bin 之前出现在 $PATH 中(如果有)。您可以通过命令查看环境中您的Java版本java -version。 learningloop的另一个答案非常完美,可以在不同的Java配置之间切换

回答by bryn

The Oracle JDK RPMs are horrible.

Oracle JDK RPM 非常糟糕。

  • They do not register with the alternativessystem.
  • They do not Provide(in RPM terms) "java"
  • They have messed up their RPM 'version string' and rely on Epoch (...)
  • All versions of the JDK (i.e. 1.6 vs 1.7) have the same Epoch
  • 他们不注册替代系统。
  • 他们不提供(以 RPM 术语)“java”
  • 他们弄乱了他们的 RPM '版本字符串' 并依赖于 Epoch (...)
  • JDK 的所有版本(即 1.6 与 1.7)都具有相同的 Epoch

In order to quickly remedy your problem you can run the following:

为了快速解决您的问题,您可以运行以下命令:

/usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000

It will register and prefer the Oracle java installation as an alternative. OpenJDK has weight 16000; here we register with 20000. Once you've run this command you can switch between java versions by using the (already mentioned) alternatives --config javacommand.

它将注册并首选 Oracle java 安装作为替代。OpenJDK 权重 16000;这里我们注册了 20000。一旦你运行了这个命令,你就可以使用(已经提到的)alternatives --config java命令在 java 版本之间切换。

As for a less quick fix you can use my virtual java package. It's quite possibly not perfect (I'm open for improvements ;) ), but it Providesjava (making my apache-tomcat package happy) and registers with the alternatives system. This virtual package simply depends on jdk...you can find it here: https://github.com/keystep/virtual-java-rpm

至于不太快速的修复,您可以使用我的虚拟 java 包。它很可能不完美(我愿意改进;)),但它提供了java(使我的 apache-tomcat 包满意)并在替代系统中注册。这个虚拟包只依赖于jdk...你可以在这里找到它:https: //github.com/keystep/virtual-java-rpm

回答by Matrix

Try to the following method

试试下面的方法

delete OpenJDK folder from

从中删除 OpenJDK 文件夹

/usr/lib/jvm

I had same problem and got solution through this method

我遇到了同样的问题并通过这种方法得到了解决