如果在Ubuntu上安装了多个Java版本,如何检查Oracle Java版本

时间:2022-03-18 07:00:04

I have both OpenJDK and Oracle Java installed on my Ubuntu. If the activated java is OpenJDK, is there a way to check the version of Oracle java in bash shell?

我在Ubuntu上安装了OpenJDK和Oracle Java。如果激活的java是OpenJDK,那么是否有办法在bash shell中检查Oracle java的版本?

5 个解决方案

#1


17  

update-java-alternatives -l will list all the java versions installed via the alternatives system.

更新-java-替代-l将列出通过替代系统安装的所有java版本。

For instance on one of my systems it will display the version and the path:

例如,在我的一个系统中,它将显示版本和路径:

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-7-oracle 1069 /usr/lib/jvm/java-7-oracle

If you want the oracle one then I guess you could do:

如果你想要神谕,我想你可以这样做:

update-java-alternatives -l | grep oracle | awk '{ print $1 }'

This would alternatively find all oracle versions and issue the -version command against each one in the list:

也可以找到所有oracle版本,并针对列表中的每个版本发出-version命令:

update-java-alternatives -l | grep oracle | awk '{system($3"/bin/java -version")}'

Output may look something like this:

输出可能如下所示:

java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

One step further would be to parse out the java version from the -version command and simply display it:

进一步的一步是从-version命令中解析java版本,并简单地显示它:

(update-java-alternatives -l | grep oracle | awk '{system(""$3"/bin/java -version 2>&1 | grep \"java version\"")}') | awk -F\" '{print $2}'

The 2>&1 is needed because Java will display version to standard error. The output would simply look like this (and could be easily assigned to a bash variable if you needed it that way):

需要2>和1,因为Java将显示标准错误版本。输出就像这样(如果需要的话,可以很容易地分配给bash变量):

1.7.0_67

If you had multiple oracle instances this would display the version for each one. If you wanted to find all the versions for every Java you could simply remove the | grep oracle

如果您有多个oracle实例,将会显示每个实例的版本。如果您想要找到每个Java的所有版本,只需删除| grep oracle

#2


7  

If you are using the openjdk java, then the oracle Java in your PC is just a folder. There is no command to check the version of that if you are not using it.

如果您正在使用openjdk java,那么您的PC中的oracle java只是一个文件夹。如果您不使用它,没有命令来检查版本。

If you once used oracle java then it must be in your java alternatives and you can find the folder (usually with version in name) with:

如果您曾经使用过oracle java,那么它必须在您的java替代品中,您可以找到包含以下内容的文件夹(通常名称中包含版本):

update-alternatives --config java

If it says something like /usr/lib/jvm/jdk1.8.0_05/bin/java, then you have 1.8 in your pc.

如果它说像/usr/ lib/jvmk1.8.0_05 /bin/java这样的东西,那么您的pc中就有1.8个。

If you haven't used oracle java anytime you simply have to check what you have downloaded.

如果您没有使用oracle java,那么您只需检查您下载的内容。

If you want to simply see the version you are using:

如果你想简单地看到你正在使用的版本:

java -version

Hope it helps

希望它能帮助

#3


2  

yes, you need to know the install path of the oracle one. then /path/to/there/bin/java -version. Assume that the openjdk one is your default java.

是的,您需要知道oracle的安装路径。然后/路径/ / / bin / java - version。假设openjdk是您的默认java。

#4


1  

Go to the installation folder of the oracle Java, and then open the bin folder. Now open a terminal "here" and type java -version

转到oracle Java的安装文件夹,然后打开bin文件夹。现在打开终端“here”,输入java -version

alternativelly,

paste the entire path to that bin folder in the command line followed by java -version i.e. /path/to/bin/java -version

另一种方法是,将整个路径粘贴到命令行中的bin文件夹,然后是java -version,即/path/to/bin/java -version

#5


1  

you should follow bellow two commands

您应该遵循以下两个命令。

  1. sudo update-alternatives --config java
  2. sudo update-alternatives——配置java

In their show the all already installed Java versions like below如果在Ubuntu上安装了多个Java版本,如何检查Oracle Java版本

在他们的展示中,所有已经安装的Java版本如下所示

2.gedit ~/.bashrc

2。中~ / . bashrc

`export JAVA_HOME=/path/to/jdk/folder

'出口JAVA_HOME = /道路/ / jdk /文件夹

usually /usr/java/jdk or /usr/lib/java/jdk

export PATH=$PATH:$JAVA_HOME/bin`

导出路径= $路径:$ JAVA_HOME / bin '

add to bash

添加到bash

#1


17  

update-java-alternatives -l will list all the java versions installed via the alternatives system.

更新-java-替代-l将列出通过替代系统安装的所有java版本。

For instance on one of my systems it will display the version and the path:

例如,在我的一个系统中,它将显示版本和路径:

java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64
java-7-oracle 1069 /usr/lib/jvm/java-7-oracle

If you want the oracle one then I guess you could do:

如果你想要神谕,我想你可以这样做:

update-java-alternatives -l | grep oracle | awk '{ print $1 }'

This would alternatively find all oracle versions and issue the -version command against each one in the list:

也可以找到所有oracle版本,并针对列表中的每个版本发出-version命令:

update-java-alternatives -l | grep oracle | awk '{system($3"/bin/java -version")}'

Output may look something like this:

输出可能如下所示:

java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

One step further would be to parse out the java version from the -version command and simply display it:

进一步的一步是从-version命令中解析java版本,并简单地显示它:

(update-java-alternatives -l | grep oracle | awk '{system(""$3"/bin/java -version 2>&1 | grep \"java version\"")}') | awk -F\" '{print $2}'

The 2>&1 is needed because Java will display version to standard error. The output would simply look like this (and could be easily assigned to a bash variable if you needed it that way):

需要2>和1,因为Java将显示标准错误版本。输出就像这样(如果需要的话,可以很容易地分配给bash变量):

1.7.0_67

If you had multiple oracle instances this would display the version for each one. If you wanted to find all the versions for every Java you could simply remove the | grep oracle

如果您有多个oracle实例,将会显示每个实例的版本。如果您想要找到每个Java的所有版本,只需删除| grep oracle

#2


7  

If you are using the openjdk java, then the oracle Java in your PC is just a folder. There is no command to check the version of that if you are not using it.

如果您正在使用openjdk java,那么您的PC中的oracle java只是一个文件夹。如果您不使用它,没有命令来检查版本。

If you once used oracle java then it must be in your java alternatives and you can find the folder (usually with version in name) with:

如果您曾经使用过oracle java,那么它必须在您的java替代品中,您可以找到包含以下内容的文件夹(通常名称中包含版本):

update-alternatives --config java

If it says something like /usr/lib/jvm/jdk1.8.0_05/bin/java, then you have 1.8 in your pc.

如果它说像/usr/ lib/jvmk1.8.0_05 /bin/java这样的东西,那么您的pc中就有1.8个。

If you haven't used oracle java anytime you simply have to check what you have downloaded.

如果您没有使用oracle java,那么您只需检查您下载的内容。

If you want to simply see the version you are using:

如果你想简单地看到你正在使用的版本:

java -version

Hope it helps

希望它能帮助

#3


2  

yes, you need to know the install path of the oracle one. then /path/to/there/bin/java -version. Assume that the openjdk one is your default java.

是的,您需要知道oracle的安装路径。然后/路径/ / / bin / java - version。假设openjdk是您的默认java。

#4


1  

Go to the installation folder of the oracle Java, and then open the bin folder. Now open a terminal "here" and type java -version

转到oracle Java的安装文件夹,然后打开bin文件夹。现在打开终端“here”,输入java -version

alternativelly,

paste the entire path to that bin folder in the command line followed by java -version i.e. /path/to/bin/java -version

另一种方法是,将整个路径粘贴到命令行中的bin文件夹,然后是java -version,即/path/to/bin/java -version

#5


1  

you should follow bellow two commands

您应该遵循以下两个命令。

  1. sudo update-alternatives --config java
  2. sudo update-alternatives——配置java

In their show the all already installed Java versions like below如果在Ubuntu上安装了多个Java版本,如何检查Oracle Java版本

在他们的展示中,所有已经安装的Java版本如下所示

2.gedit ~/.bashrc

2。中~ / . bashrc

`export JAVA_HOME=/path/to/jdk/folder

'出口JAVA_HOME = /道路/ / jdk /文件夹

usually /usr/java/jdk or /usr/lib/java/jdk

export PATH=$PATH:$JAVA_HOME/bin`

导出路径= $路径:$ JAVA_HOME / bin '

add to bash

添加到bash