macOS中JDK安装路径:

OSX默认的JDK
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

这其实是一个符号链接,它指向:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

OS X自带的JRE
/System/Library/Frameworks/JavaVM.framework/Versions/Current

ORACLE的JDK7
/Library/Java/JavaVirtualMachines/jdk1.7.0_xx.jdk/Contents/Home

ORACLE的JRE7
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

OPENJDK7
/Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Home

配置过程:

1、启动终端,可以在Spotlight中搜索“终端”

2、进入当前用户的HOME目录

cd $HOME

3、创建“.bash_profile”文件(当该文件不存在时),如果文件已存在,直接打开文件即可

touch .bash_profile

4、打开.bash_profile文件,对其内容进行编辑

open -e .bash_profile

5、此时文本编辑器会打开一个文本,增加如下内容

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
CLASSPAHT=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH:
export JAVA_HOME
export CLASSPATH
export PATH
JAVA_HOME为JDK安装路径

6、保存文件,关闭.bash_profile

7、更新刚配置的环境变量,在终端执行命令

source .bash_profile

8、验证配置是否成功

appledeMac-mini:~ zhaikun$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

JDK环境变量配置路径:

appledeMac-mini:~ zhaikun$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

以上配置只能在当前用户中使用

参考文档:https://www.cnblogs.com/cuiliang/p/4603762.html

参考文档:https://blog.csdn.net/binbinzheng/article/details/46621639