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 Javawhich java## check Java versionjava-version
Take zsh as an example:
# # Check all the available JDK 2/usr/libexec/java_home-v 3 4 # # Check the top JDK 5/usr/libexec/java_home 6 7 # # Check some jdk (eg. version 1.7) 8/usr/libexec/java_home-v 1.7 9 # # Edit. ZSHRC to set Java_home variable11 vim ~/. ZSHRC12 # # Add the following line into the FILE14 export java_home=$ (/usr/libexec/java_home) # # # You can also use T He following line to set the variable, which are not recommended, only for older Mac os.17 # # Export JAVA_HOME=/SYSTEM/LIBR Ary/java/javavirtualmachines/1.6.0.jdk/contents/home18 # #let the configuration in. ZSHRC take effect20 source ~/. ZSHRC21 # # # Check if configure Succeed23 echo $JAVA _home
"Java" MAC configuration JAVA environment variables