在Centos下用alternatives命令切换JDK版本
日期:2017-09-27 阅读:4863 分类:学无止境 标签:JDK LAMP Linux
Centos自带了openJDK,且有好几个版本,用alternatives命令就可以切换版本;
然,新项目需要jdk1.8,于是从官网下载了jdk-8u144-linux-x64.tar.gz进行安装;
tar解压到/usr/local/smartCms/java/
下一步,将新装的JDK版本登记到alternatives里面,输入如下命令
alternatives --install /usr/bin/java java /usr/local/smartCms/java/jdk1.8.0_144/bin/java 1 alternatives --install /usr/bin/javac javac /usr/local/smartCms/java/jdk1.8.0_144/bin/javac 1 alternatives --install /usr/bin/jar jar /usr/local/smartCms/java/jdk1.8.0_144/bin/jar 1
然后运行alternatives --config java就可以选择所需的jdk版本了
[root@ctcm java]# alternatives --config java 共有 5 个程序提供“java”。 选择 命令 ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java 2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java 3 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java 4 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64/jre/bin/java + 5 /usr/local/smartCms/java/jdk1.8.0_144/bin/java 按 Enter 来保存当前选择[+],或键入选择号码:5
选择5,就切换到新装的JDK了,查看下版本
[root@ctcm java]# java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
OK,搞定;