Centos多版本Java切换
我在/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
需要把之前配置的环境变量删除:
使用:
alternatives --config java
删除:
alternatives --remove java /root/tools/java/jdk-21.0.3/bin/java
alternatives --remove java /root/tools/java/jdk1.8.0_411/bin/java