Last active
November 12, 2017 13:53
-
-
Save emedinaa/f11d353e9a8eccdd9cc8395a954f25ff to your computer and use it in GitHub Desktop.
Set-JAVA_HOME
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to set JAVA_HOME on Mac OS X | |
$ echo $JAVA_HOME | |
/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home | |
Download JDK 8 from Oracle WebSite. [jdk-8u74-macosx-x64.dmg for Mac]. | |
Double click on jdk-8u74-macosx-x64.dmg and follow the screen instructions. | |
JDK package will have been installed on /Library/Java/JavaVirtualMachines. In my computer, I have both 8u66 and 8u74 JDK package. | |
$ ls -l /Library/Java/JavaVirtualMachines | |
drwxr-xr-x 3 root wheel 102 23 dic 20:36 jdk1.8.0_66.jdk | |
drwxr-xr-x 3 root wheel 102 21 mar 14:20 jdk1.8.0_74.jdk | |
Open and edit .bash_profile file. If the file does not exist, check out this link. | |
$ open -e .bash_profile | |
Save the below line. This let us use the newest JDK version installed on our computer. | |
export JAVA_HOME=$(/usr/libexec/java_home) | |
Refresh the file using below command | |
$ source .bash_profile | |
Check if the JAVA_HOME is set properly | |
$ echo $JAVA_HOME | |
/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home | |
Another way: | |
$ java -version | |
java version "1.8.0_74" | |
Java(TM) SE Runtime Environment (build 1.8.0_74-b02) | |
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) | |
Sometimes, we need to downgrade the $JAVA_HOME environment variable. First, check theses commands: | |
## Return top Java version | |
$ (/usr/libexec/java_home) | |
/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home | |
## Return a specific Java version | |
$ (/usr/libexec/java_home -v 1.8.0_66) | |
/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home | |
Theses commands give us the top or a specific Java version. Therefore, we can set $JAVA_HOME environment variable by modifying the .bash_profile file. | |
Open and edit .bash_profile file | |
$ open -e .bash_profile | |
Save the below line. This let us use the newest JDK version installed on our computer. | |
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_66) | |
Refresh the file using below command | |
$ source .bash_profile | |
Check if the JAVA_HOME is set properly | |
$ echo $JAVA_HOME | |
/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment