Linux修改默认jdk

1、下载解压jdk1.8压缩包,配置环境变量

export JAVA_HOME=/usr/local/jdk1.8.0_181   -- jdk所在目录
export JRE_HOME=/usr/local/jdk1.8.0_181/jre -- jre所在目录
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

2、source+环境配置文件,立即生效

3、测试是否修改成功?

java -version

如果没有继续看

4、没有新安装的1.8.1版本jdk,需要使用命令将新安装的jdk放入到java bin中

4.1 查看已有jdk

[root@CentOS ~]# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/lib/jvm/jre-1.5.0-gcj/bin/java

可以看到只有三个,没有刚安装的1.8版本,记住此时有3个已默认安装的jdk版本

4.2 现在我们要添加第四个,注意命令中数字4的含义是:配置第四个jdk

alternatives --install /usr/bin/java java /usr/local/jdk1.8.0_181/bin/java 4

4.3 使用alternatives --config java修改默认jdk版本

[root@CentOS ~]# alternatives --config java

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
   4           /usr/local/jdk1.8.0_181/bin/java

Enter to keep the current selection[+], or type selection number: 4
[root@CentOS ~]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

 

你可能感兴趣的:(工欲善其事必先利其器,J2SE)