mac电脑安装了jdk8、jdk11、jdk21 三个版本的jdk,在环境变量中配置命令,动态切换不同jdk
1.下载JDK,Mac建议下载xxxxx/jdk-21_macos-x64_bin.dmg
https://download.oracle.com/java/21/latest/jdk-21_macos-x64_bin.dmg,
2.双击安装,会安装在 /Library/Java/JavaVirtualMachines/jdk-21.jdk/ 目录
3.配置环境变量和自定义切换命令 vi ~/.bash_profile
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
export JAVA_11_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home
export JAVA_21_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
alias jdk11='export JAVA_HOME=$JAVA_11_HOME'
alias jdk21='export JAVA_HOME=$JAVA_21_HOME'
4.使其生效:source ~/.bash_profile
5.在命令行输入 jdk8 切换到 jdk8,输入jdk21 切换到21