1.創(chuàng)建.bash_profile
如果是第一次配置環(huán)境變量湾盒,可以使用"touch .bash_profile" 創(chuàng)建一個(gè) .bash_profile 的隱藏配置文件(如果已經(jīng)有存在的配置文件湿右,則使用"open -e .bash_profile" 命令)
touch .bash_profile
open -e .bash_profile
2.編輯.bash_profile文件
JAVA_HOME填寫自己的Java路徑
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
PATH=PATH:.
CLASSPATH=JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
3.使用.bash_profile文件
使配置生效
source .bash_profile
輸入 echo $JAVA_HOME 命令顯示剛才配置的路
echo $JAVA_HOME