![java 1.7.0_67 installation on mac java 1.7.0_67 installation on mac](https://codenotfound.com/assets/images/posts/java/java-7-jdk-location.png)
This answer is an attempt to address: how to control java version system-wide (not just in currently running shell) when several versions of JDK are installed for development purposes on macOS El Capitan or newer (Sierra, High Sierra, Mojave). Press Y to save your changes source ~/.zshrc
![java 1.7.0_67 installation on mac java 1.7.0_67 installation on mac](https://1.bp.blogspot.com/-GRPs8PnB32M/XwG-vve1pJI/AAAAAAAACzc/h_qBfZFWVpo-n0vnOvbuGx6YuWXJUDDpQCLcBGAsYHQ/s1600/How%2Bto%2Binstall%2BJava%2B8%2Bon%2BMac%3F%2BInstalling%2BJava%2B8%2Bon%2BLatest%2BMac%2BOS%2BX%2B%28HomeBrew%2BGuide%29.png)
zshrc file should work: nano ~/.zshrcĮxport JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)Īdd the export JAVA_HOME… line to your shell’s init file.įor Bash (as stated by antonyh): export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)įor Fish (as stated by ormurin) set -x JAVA_HOME (/usr/libexec/java_home -d64 -v1.8) Now when you run java -version you will see: java version "1.6.0_65" Or you can specify just the major version, like: export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
![java 1.7.0_67 installation on mac java 1.7.0_67 installation on mac](http://4.bp.blogspot.com/-rqKNxf-fz4k/UF_2y7mIAjI/AAAAAAAAIW0/xJW5WxRVpBM/s1600/macosx-java7-version-terminal.png)
Pick the version you want to be the default ( 1.6.0_65-b14-462 for arguments sake) then: export JAVA_HOME=`/usr/libexec/java_home -v 1.6.0_65-b14-462` Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home First run /usr/libexec/java_home -V which will output something like the following: Matching Java Virtual Machines (3):ġ.8.0_05, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Homeġ.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Homeġ.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home