ubantu检查java 版本,如何检查甲骨文的Java版本,如果多个Java版本安装在Ubuntu

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?

解决方案

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

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:

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:

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值