Reference: http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/
If you use bash, modify ~/.bash_profile
or~/.profile;
If you use zsh, modify the ~/.ZSHRC
After modifying these files, re-open terminal, the configuration will not be lost
First make sure the JDK is installed:
# # Check the present running Java which -version
Take zsh as an example:
1 # # Check all the available JDK2/usr/libexec/java_home-V3 4 # # Check the top JDK5/usr/libexec/Java_home6 7# # Check some jdk (eg. version1.7)8/usr/libexec/java_home-v1.79 Ten # # Edit. ZSHRC to set java_home variable OneVim ~/. ZSHRC A -# # Add the following line into thefile -Export java_home=$ (/usr/libexec/java_home) the -# # You can also with the following line to set the variable,whichIs isn't recommended, only forolder Mac OS. -# # Export Java_home=/system/library/java/javavirtualmachines/1.6.0. jdk/contents/Home - +# #let the configurationinch. ZSHRC take effect -SOURCE ~/. ZSHRC + A# # CheckifConfigure succeed at Echo$JAVA _home
Mac set Java environment variables, using OH-MY-ZSH