configure bash_profile
- Execute the following command in the Mac terminal to see the Java installation directory
/usr/libexec/java_home
# 输出:
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
- Execute the command
vim ./bash_profile
Enter bash_profile editing and add the following configuration at the end:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib
- Then execute the command
source ~/.bash_profile
to make the configuration take effect. - Finally execute
echo $JAVA_HOME
to verify whether the configuration takes effect:
echo $JAVA_HOME
# 如果能正确输出Java安装目录,则说明配置已生效
/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
Configure JAVA_HOME when oh_my_zsh is installed
If oh_my_zsh has been installed on Mac, then executing source ~/.bash_profile
will change the terminal style back to the previous bash style. In this case, to configure JAVA_HOME, the previous steps are still the same. The only thing that needs to be modified is to add source ~/.bash_profile
to the ~/.zshrc file. The operation is as follows:
- Execute command
vim ~/.zshrc
Enter ~/.zshrc file editing - Insert
source ~/.bash_profile
into the file, it is recommended to add this line beforesource $ZSH/oh-my-zsh.sh
- Execute the command
source ~/.zshrc
to make the configuration take effect - Finally, you can also execute
echo $JAVA_HOME
to verify whether the configuration is effective