安装JDK1.7后发现版本不对,默认是系统自带的JDK1.8。需要更改,这里使用alternatives处理,参照http://blog.youkuaiyun.com/nsrainbow/article/details/43273991文章, 下附原文内容,备忘。只不过自己是rpm安装的,不需要install 拷贝过去。
centos自带openJDK,我从别的机器上拷贝了一个dk1.7 到 /usr/java/ 目录下,然后运行
sudo alternatives --install /usr/bin/java java /opt/jdk1.7.0_71/bin/java 1 sudo alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_71/bin/javac 1 sudo alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_71/bin/jar 1
这样就登记了一个新的jdk在 alternatives 里面
然后运行 alternatives --config java 会出现两个jdk让我选
[root@host1 java]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java + 2 /usr/java/jdk1.7.0_25/bin/java Enter to keep the current selection[+], or type selection number: 2
我选2,jdk就切换成 oracle jdk了
[root@host1 java]# java -version java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
后来发现alternatives 还是很好用的:
[root@mongod_2 ~]# vim ./hello.sh #!/bin/bash # ver="0.1" echo $ver [root@mongod_2 ~]# cp hello.sh hello2.sh [root@mongod_2 ~]# vim hello2.sh #!bin/bash # ver="0.2" echo $ver [root@mongod_2 ~]# alternatives --install /usr/local/hello hello /root/hello.sh 1 [root@mongod_2 ~]# alternatives --install /usr/local/hello hello /root/hello2.sh 1 [root@mongod_2 ~]# alternatives --config hello [root@mongod_2 ~]# alternatives --config hello There are 2 programs which provide 'hello'. Selection Command ----------------------------------------------- * 1 /root/hello.sh + 2 /root/hello2.sh
转载于:https://blog.51cto.com/kingslanding/1827076