macos M1安装多个版本jdk

1、安装jdk 8
到 oracle 官网
https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html

找到 macOS x64 DMG Installer 后面的下载链接下载安装包

java的jdk 都安装在以下目录

ls /Library/Java/JavaVirtualMachines/

jdk-1.8.jdk		jdk-11.0.12.jdk		jdk-17.0.4.1.jdk	jdk1.8.0_202.jdk

vim ~/.bash_profile 添加以下环境变量

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH

source ~/.bash_profile 让配置生效,然后执行以下命令,检测jdk 8是否安装成功

javac -version
javac 1.8.0_371

java -version
java version "1.8.0_371"
Java(TM) SE Runtime Environment (build 1.8.0_371-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.371-b11, mixed mode)

你可能感兴趣的:(macos,java,开发语言)