Mac M1 安装 JDK 及动态切换版本
写在最前
本示例以 Azul Java8 和 Oracle Java8 为例,实现动态切换两个版本的 JDK8。
下载安装
-
Azul ARM JDK:www.azul.com/downloads/?…
-
Oracle X86 JDK: www.oracle.com/java/techno…
安装完成后,终端输入
java -version
查看当前 JDK 版本
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (Zulu 8.68.0.19-CA-macos-aarch64) (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (Zulu 8.68.0.19-CA-macos-aarch64) (build 25.362-b08, mixed mode)
配置环境
1. 编辑配置文件
vim ~/.bash_profile
2. 配置 JDK 信息
# 配置JDK路径
export AZUL_JAVA_8_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
# 设置默认JDK版本
export JAVA_HOME=$AZUL_JAVA_8_HOME
# 配置alias命令可以动态切换JDK版本
alias zual_jdk8="export JAVA_HOME=$AZUL_JAVA_8_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
export JAVA_HOME
export PATH
export CLASSPATH
3. 立即将配置文件生效
source ~/.bash_profile
4. 验证配置
stive@StivedeMacBook-Pro ~ % zual_jdk8
stive@StivedeMacBook-Pro ~ % java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (Zulu 8.68.0.19-CA-macos-aarch64) (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (Zulu 8.68.0.19-CA-macos-aarch64) (build 25.362-b08, mixed mode)
stive@StivedeMacBook-Pro ~ % jdk8
stive@StivedeMacBook-Pro ~ % java -version
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)
5. 查看 JDK 路径
echo $JAVA_HOME
卸载 JDK
1. 查看安装的 JDK 版本
cd /Library/Java/JavaVirtualMachines
ls
2. 卸载指定版本
sudo rm -rf /Library/Java/JavaVirtualMachines/版本号
# 例如
sudo rm -rf /Library/Java/JavaVirtualMachines/zulu-8.jdk
3. 删除运行路径和运行环境等
$sudo rm -fr /Library/Internet/Plug-Ins/JavaAppletPlugin.plugin
$sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefPane
$sudo rm -fr ~/Library/Application/Support/Java
转载自:https://juejin.cn/post/7215781742479671352