且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我的机器上同时安装多个版本的Java JDK?

更新时间:2023-09-14 23:33:10

解决方案



显然,RPM脚本是Oracle版本倾向于通过从旧版安装中删除关键JAR文件来破坏您安装的任何以前的JDK版本,例如 tools.jar rt的.jar 。这使得以前运行的JDK对开发人员无用。

Solution

Apparently, the RPM scripts that Oracle releases tend to break any previous JDK versions you have installed by way of removing key JAR files from those older installations, such as tools.jar and rt.jar. This renders the formerly functioning JDK useless for developers.

我的第一个响应是在运行第二个安装程序脚本之前重命名安装目录。但这样做会让RPM抱怨在运行第二个脚本时已经安装了JDK版本。因此黑客入侵是安装一个版本,重命名该目录,然后用RPM删除该版本(即使它会抱怨无法找到与之关联的任何相应文件)。 然后您可以***安装第二个版本,为每个版本重复前面的步骤,直到您找到要安装的最新版本。

My first response was to rename the installation directory prior to running the second installer script. But doing that made RPM complain about already having a version of the JDK installed when running the second script. So the hack of the hack is to install one version, rename that directory, then "remove" that version with RPM (even though it will complain about not being able to find any of the respective files associated with it). Then you are free to install the second version, repeating the previous steps for each one until you get to the latest version you wish to install.

以下是在同一台机器上获取多个正在运行的JDK版本的步骤:

Here are the steps to get multiple working JDK versions on the same machine:

1。使用安装程序脚本安装第一版JDK:

:~# chmod a+x jdk-1_5_0_22-linux-amd64-rpm.bin
:~# ./jdk-1_5_0_22-linux-amd64-rpm.bin -x
:~# rpm -ivh --replacepkgs jdk-1_5_0_22-linux-amd64.rpm

2。重命名安装目录:

:~# mv /usr/java/jdk1.5.0_22 /usr/java/jdk1.5.0_22-bak

3。使用RPM卸载该版本的JDK:

:~# rpm -e jdk-2000:1.5.0_22-fcs.x86_64

4。冲洗并重复直至安装所有版本

5。从目录名称的末尾删除 -bak

5. Remove the -bak from the end of the directory names

:~# mv /usr/java/jdk1.5.0_22-bak /usr/java/jdk1.5.0_22

6。将 / usr / java 符号链接更改为正确的目标:

6. Change the /usr/java symlinks to the correct target:

:~# ls -la /usr/java
default -> java7
java5 -> jdk1.5.0_22
java6 -> jdk1.6.0_45
java7 -> jdk1.7.0_80
java8 -> jdk1.8.0_101
jdk1.5.0_22
jdk1.6.0_45
jdk1.7.0_80
jdk1.8.0_101
latest -> java8

7。将 / usr / bin 符号链接更改为正确的目标:

7. Change the /usr/bin symlinks to the correct target:

:~# ls -la /usr/bin/ja*
jar -> /usr/java/default/bin/jar
java -> /usr/java/default/bin/java
javac -> /usr/java/default/bin/javac
javadoc -> /usr/java/default/bin/javadoc
javah -> /usr/java/default/bin/javah
javaws -> /usr/java/default/bin/javaws