Ubuntu:改变从OpenJDK 6到Oracle JDK 7的路径。

时间:2021-01-12 23:49:00

After downloading the latest .tar file I ran tar zxvf jdk-7u45-linux-x64.tar.gz to extract java files.

在下载最新的.tar文件后,我运行了tar zxvf jdk-7u45-linux-x64.tar。gz来提取java文件。

Set the path in .bashrc file (vi ~/.bashrc) as below;

将路径设置为.bashrc文件(vi ~/.bashrc)如下;

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45/bin/java
export PATH=$PATH:/usr/lib/jvm/jdk1.7.0_45/bin
export JDK_HOME=/usr/lib/jvm/jdk1.7.0_45    
export JRE_HOME=/usr/lib/jvm/jre1.7.0_45

Now, running command java -version or which java, java PATH still pointing to the older java version (java version "1.6.0_27").

现在,运行命令java -版本或java, java路径仍然指向旧的java版本(java版本“1.6.0_27”)。

I know default ubuntu takes OpenJDK path. I have to change the path as latest version as my system environment variable set in .bashrc file.

我知道默认ubuntu采用的是OpenJDK路径。我必须将路径作为最新的版本,作为我的系统环境变量设置在.bashrc文件中。

Also, sudo update-alternatives --config java

另外,sudo update- options——config java。

Selection    Path                                      Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-oracle/jre/bin/java    1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java    1062      manual mode
* 3            /usr/lib/jvm/jdk1.7.0_45/bin/java          1         manual mode
Press enter to keep the current choice[*], or type selection number: 3

5 个解决方案

#1


36  

Ubuntu (and Debian) have an elegant way to manage libraries like the jdk.

Ubuntu(和Debian)有一种优雅的方式来管理像jdk这样的库。

Using update-alternatives you can manage multiple jdk libraries on the same system, choosing which one you want to use as the main one.

使用update-替代品,您可以在同一个系统上管理多个jdk库,选择您想要用作主要的库。

First you have to install an alternative for the new installed jdk:

首先,您必须为新安装的jdk安装一个替代方案:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_45/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_45/bin/javac" 1

In this way you install the new jdk as an alternative to the original one. Then you can choose which one you wan to use:

通过这种方式,您可以将新jdk安装为与原始jdk的替代品。然后你可以选择使用哪一个:

sudo update-alternatives --config java
sudo update-alternatives --config javac

You will be asked to choose which jdk you want to use, on my system I have:

您将被要求选择您想要使用的jdk,在我的系统中:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 

At any time you can see what alternatives you have for java or javac using the --list option:

在任何时候,您都可以使用—list选项来查看您对java或javac的替代选择:

sudo update-alternatives --list java
sudo update-alternatives --list javac

To see more options check the update-alternatives man page.

要查看更多选项,请查看updateoptions手册页。

#2


8  

You probably want to do

你可能想做。

export PATH=/usr/lib/jvm/jdk1.7.0_45/bin:$PATH

OpenJDK is probably still in the path, and Linux will use the first java it finds.

OpenJDK可能还在运行中,Linux将使用它找到的第一个java。

If you don't need it, I would recommend uninstalling OpenJDK.

如果您不需要它,我建议卸载OpenJDK。

#3


4  

Try typing the following in your terminal.

尝试在终端输入以下内容。

sudo update-alternatives --config java

sudo update-alternatives——配置java

The output will be some choices and you can select the correct one which installed to your computer.

输出将是一些选择,您可以选择正确的安装到您的计算机。

#4


4  

Running command in terminal:

在终端运行命令:

sudo update-alternatives --config java 

from the command line to set the version of the JRE you want to use as like available version install of java : 1.6 and 1.8
See below :

从命令行中设置您想要使用的JRE版本,就像java的可用版本安装:1.6和1.8如下:

Ubuntu:改变从OpenJDK 6到Oracle JDK 7的路径。

and choose 1 option and set java-6 version because already current choice set in java-8.

选择1个选项并设置java-6版本,因为已经在java-8中设置了当前的选择。

#5


3  

Run

运行

sudo  update-java-alternatives --list

to list off all the Java installations on a machine by name and directory, and then run

在机器上按名称和目录列出所有的Java安装,然后运行。

sudo  update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]

to choose which JRE/JDK to use.

选择要使用的JRE/JDK。

If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run

如果您想为每个Java任务使用不同的jdk /JREs,您可以运行更新替代方案,一次配置一个Java可执行文件;您可以运行

sudo  update-alternatives --config java[Tab]

to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then

要查看可配置的Java命令(Java、javac、javah、javaws等)。然后

sudo  update-alternatives --config [javac|java|javadoc|etc.]

will associate that Java task/command to a particular JDK/JRE.

将该Java任务/命令关联到特定的JDK/JRE。

You may also need to set JAVA_HOME for some applications: from this answer you can use

您可能还需要为一些应用程序设置JAVA_HOME:从这个答案可以使用。

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

for JREs, or

jre,或者

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")

for JDKs.

jdk。

#1


36  

Ubuntu (and Debian) have an elegant way to manage libraries like the jdk.

Ubuntu(和Debian)有一种优雅的方式来管理像jdk这样的库。

Using update-alternatives you can manage multiple jdk libraries on the same system, choosing which one you want to use as the main one.

使用update-替代品,您可以在同一个系统上管理多个jdk库,选择您想要用作主要的库。

First you have to install an alternative for the new installed jdk:

首先,您必须为新安装的jdk安装一个替代方案:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_45/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_45/bin/javac" 1

In this way you install the new jdk as an alternative to the original one. Then you can choose which one you wan to use:

通过这种方式,您可以将新jdk安装为与原始jdk的替代品。然后你可以选择使用哪一个:

sudo update-alternatives --config java
sudo update-alternatives --config javac

You will be asked to choose which jdk you want to use, on my system I have:

您将被要求选择您想要使用的jdk,在我的系统中:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number: 

At any time you can see what alternatives you have for java or javac using the --list option:

在任何时候,您都可以使用—list选项来查看您对java或javac的替代选择:

sudo update-alternatives --list java
sudo update-alternatives --list javac

To see more options check the update-alternatives man page.

要查看更多选项,请查看updateoptions手册页。

#2


8  

You probably want to do

你可能想做。

export PATH=/usr/lib/jvm/jdk1.7.0_45/bin:$PATH

OpenJDK is probably still in the path, and Linux will use the first java it finds.

OpenJDK可能还在运行中,Linux将使用它找到的第一个java。

If you don't need it, I would recommend uninstalling OpenJDK.

如果您不需要它,我建议卸载OpenJDK。

#3


4  

Try typing the following in your terminal.

尝试在终端输入以下内容。

sudo update-alternatives --config java

sudo update-alternatives——配置java

The output will be some choices and you can select the correct one which installed to your computer.

输出将是一些选择,您可以选择正确的安装到您的计算机。

#4


4  

Running command in terminal:

在终端运行命令:

sudo update-alternatives --config java 

from the command line to set the version of the JRE you want to use as like available version install of java : 1.6 and 1.8
See below :

从命令行中设置您想要使用的JRE版本,就像java的可用版本安装:1.6和1.8如下:

Ubuntu:改变从OpenJDK 6到Oracle JDK 7的路径。

and choose 1 option and set java-6 version because already current choice set in java-8.

选择1个选项并设置java-6版本,因为已经在java-8中设置了当前的选择。

#5


3  

Run

运行

sudo  update-java-alternatives --list

to list off all the Java installations on a machine by name and directory, and then run

在机器上按名称和目录列出所有的Java安装,然后运行。

sudo  update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]

to choose which JRE/JDK to use.

选择要使用的JRE/JDK。

If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run

如果您想为每个Java任务使用不同的jdk /JREs,您可以运行更新替代方案,一次配置一个Java可执行文件;您可以运行

sudo  update-alternatives --config java[Tab]

to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then

要查看可配置的Java命令(Java、javac、javah、javaws等)。然后

sudo  update-alternatives --config [javac|java|javadoc|etc.]

will associate that Java task/command to a particular JDK/JRE.

将该Java任务/命令关联到特定的JDK/JRE。

You may also need to set JAVA_HOME for some applications: from this answer you can use

您可能还需要为一些应用程序设置JAVA_HOME:从这个答案可以使用。

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

for JREs, or

jre,或者

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")

for JDKs.

jdk。