JDK下载网址https://www.oracle.com/java/technologies/downloads/
下载选择macOS成功后直接安装根据指示安装即可
打开终端执行命令: java -version可查看版本
ava -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)
查看安装的路径:/usr/libexec/java_home -V
/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.361.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_361 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
创建设置环境文件:touch .bash_profile(如果有了该文件就不用创建)
打开设置环境文件:open -e .bash_profile
设置环境变量
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home(文件位置)
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
执行保存环境变量:source .bash_profile
查看是否成功:echo $JAVA_HOME
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
详细情况命令如下
来源地址:https://blog.csdn.net/weixin_44033025/article/details/130127806