下载JDK

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  1. Accept the Oracle Binary Code License Agreement for Java SE
  2. 下载Mac OS X x64版本的带.dmg后缀的JDK文件

安装

直接双击dmg文件进行安装

查看安装位置

见之前的文章:[Mac下查看已安装的jdk版本及其安装目录]

设置环境变量

1
$ vim ~/.zshrc

添加JAVA_HOME:

1
2
3
4
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home

export PATH=.:${JAVA_HOME}/bin:...
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar