如何检查甲骨文的Java版本,如果多个Java版本安装在Ubuntu [英] How to check Oracle Java version if multiple versions of Java installed on Ubuntu

查看:124
本文介绍了如何检查甲骨文的Java版本,如果多个Java版本安装在Ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都的OpenJDK 的和的甲骨文的Java 的安装在我的Ubuntu Linux系统。
如果激活Java是OpenJDK的,有没有办法来检查甲骨文的Java版本的bash shell?

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?

推荐答案

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

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

例如在我的系统之一,它会显示版本和路径:

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

如果你想在oracle之一,那么我想你可以这样做:

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

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

这或者会发现所有的Oracle版本,并发出对每一个在列表中的 -version 命令:

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

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

输出可能是这个样子:

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)

一步将解析出从 -version 命令的Java版本,只是显示它:

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

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

2 - ;&放大器; 1 需要,因为Java将显示版本标准错误。输出只会是这样的(并且可以很容易地分配给一个bash变量,如果你需要它的方式):

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):

1.7.0_67

如果你有多个Oracle实例,这将显示版本各一台。如果你想找到的所有版本每个Java,你可以简单地删除 |甲骨文的grep

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

这篇关于如何检查甲骨文的Java版本,如果多个Java版本安装在Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆