在Centos下用alternative命令切换各个版本的jdk的方法

安装JDK1.7后发现版本不对,认是系统自带的JDK1.8。需要更改,这里使用alternatives处理,参照http://blog.csdn.net/nsrainbow/article/details/43273991文章,下附原文内容,备忘。只不过自己是rpm安装的,不需要install 拷贝过去。

centos自带openJDK,我从别的机器上拷贝了一个dk1.7 到 /usr/java/ 目录下,然后运行

sudoalternatives--install/usr/bin/javajava/opt/jdk1.7.0_71/bin/java1
sudoalternatives--install/usr/bin/javacjavac/opt/jdk1.7.0_71/bin/javac1
sudoalternatives--install/usr/bin/jarjar/opt/jdk1.7.0_71/bin/jar1

这样就登记了一个新的jdk在 alternatives 里面

然后运行 alternatives --config java 会出现两个jdk让我选

[root@host1java]#alternatives--configjava

Thereare2programswhichprovide'java'.

SelectionCommand
-----------------------------------------------
*1/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
+2/usr/java/jdk1.7.0_25/bin/java

Entertokeepthecurrentselection[+],ortypeselectionnumber:2

我选2,jdk就切换成 oracle jdk了

[root@host1java]#java-version
javaversion"1.7.0_25"
Java(TM)SERuntimeEnvironment(build1.7.0_25-b15)
JavaHotSpot(TM)64-BitServerVM(build23.25-b01,mixedmode)

后来发现alternatives 还是很好用的:

[root@mongod_2~]#vim./hello.sh
#!/bin/bash
#
ver="0.1"
echo$ver
[root@mongod_2~]#cphello.shhello2.sh
[root@mongod_2~]#vimhello2.sh
#!bin/bash
#
ver="0.2"
echo$ver
[root@mongod_2~]#alternatives--install/usr/local/hellohello/root/hello.sh1
[root@mongod_2~]#alternatives--install/usr/local/hellohello/root/hello2.sh1
[root@mongod_2~]#alternatives--confighello
[root@mongod_2~]#alternatives--confighello
Thereare2programswhichprovide'hello'.
SelectionCommand
-----------------------------------------------
*1/root/hello.sh
+2/root/hello2.sh

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native