跳到主要内容

Centos多版本Java切换

image-20240707084611598

我在/root/tools/java目录下下载了两个Java的安装包

alternatives --install /usr/bin/java java /root/tools/java/jdk-21.0.3/bin/java 1
alternatives --install /usr/bin/java java /root/tools/java/jdk1.8.0_411/bin/java 2

Javac同理可以更换

alternatives --install /usr/bin/javac javac /root/tools/java/jdk-21.0.3/bin/javac 1
alternatives --install /usr/bin/javac javac /root/tools/java/jdk1.8.0_411/bin/javac 2

需要把之前配置的环境变量删除:

image-20240707085056630

使用:

alternatives --config java

image-20240707085027367

删除:

alternatives --remove java /root/tools/java/jdk-21.0.3/bin/java
alternatives --remove java /root/tools/java/jdk1.8.0_411/bin/java