mac jdk配置(系统默认or自己配置)

1、首先,mac中自带jdk配置,具体查看命令如下:

MacBook-Pro:JavaVirtualMachines root$ whereis java
/usr/bin/java
MacBook-Pro:JavaVirtualMachines root$ ls -l /usr/bin/java
lrwxr-xr-x  1 root  wheel  74 10 28 18:08 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

2、自己配置jdk
(1)下载对应jdk(默认安装目录为 /Library/Java/JavaVirtualMachines/ )
(2)执行 vi ~/.bash_profile 。插入以下代码:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/contents/home

然后添加java path环境变量:

export PATH=.:~:$JAVA_HOME/bin

(4)执行source ~/.bash_profile命令

(5)echo $JAVA_HOME,即可验证java home目录是否配置正确

MacBook-Pro:JavaVirtualMachines root$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/contents/home

(6)执行 java -version 即可看到是否已经配置成功。

MacBook-Pro:JavaVirtualMachines root$ java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

你可能感兴趣的:(mac jdk配置(系统默认or自己配置))