[英]How to check Oracle Java version if multiple versions of Java installed on Ubuntu
I have both OpenJDK and Oracle Java installed on my Ubuntu. 我的Ubuntu上安装了OpenJDK和Oracle Java 。 If the activated java is OpenJDK, is there a way to check the version of Oracle java in bash shell? 如果激活的java是OpenJDK,有没有办法在bash shell中检查Oracle java的版本?
update-java-alternatives -l
will list all the java versions installed via the alternatives system. update-java-alternatives -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: 如果你想要oracle那么我想你可以这样做:
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. 需要2>&1
,因为Java会将版本显示为标准错误。 The output would simply look like this (and could be easily assigned to a bash variable if you needed it that way): 输出看起来就像这样(如果你需要的话,可以很容易地分配给bash变量):
1.7.0_67
If you had multiple oracle instances this would display the version for each one. 如果您有多个oracle实例,则会显示每个实例的版本。 If you wanted to find all the versions for every Java you could simply remove the | grep oracle
如果你想找到每个Java的所有版本,你可以简单地删除| grep oracle
| grep oracle
If you are using the openjdk java, then the oracle Java in your PC is just a folder. 如果您使用的是openjdk java,则PC中的oracle Java只是一个文件夹。 There is no command to check the version of that if you are not using it. 如果您不使用它,则无法检查其版本。
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/jvm/jdk1.8.0_05/bin/java ,那么你的电脑里有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 希望能帮助到你
yes, you need to know the install path of the oracle one. 是的,你需要知道oracle的安装路径。 then /path/to/there/bin/java -version
. 然后/path/to/there/bin/java -version
。 Assume that the openjdk
one is your default java. 假设openjdk
是你的默认java。
Go to the installation folder of the oracle Java, and then open the bin
folder. 转到oracle Java的安装文件夹,然后打开bin
文件夹。 Now open a terminal "here" and type java -version
现在打开一个“here”终端并键入java -version
alternativelly, alternativelly,
paste the entire path to that bin folder in the command line followed by java -version
ie /path/to/bin/java -version
将整个路径粘贴到命令行中的bin文件夹,然后粘贴java -version
ie /path/to/bin/java -version
you should follow bellow two commands 你应该遵循以下两个命令
In their show the all already installed Java versions like below 在他们的节目中,所有已安装的Java版本如下所示
2.gedit ~/.bashrc 2.gedit~ / .bashrc
`export JAVA_HOME=/path/to/jdk/folder `export JAVA_HOME = / path / to / jdk / folder
export PATH=$PATH:$JAVA_HOME/bin` export PATH = $ PATH:$ JAVA_HOME / bin`
add to bash 添加到bash
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.