Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
Check you have the needed version of Java, by typing “java -version”. JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java. For Mac OSX – it is /Library/Java/Home.
The JAVA_HOME environment variable contains the home location of an installed JDK. /usr/libexec/java_home is the simplest maintainable way of setting JAVA_HOME . Set JAVA_HOME to JDK version 1.7 export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
With the Java optional package or Oracle JDK installed, adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.
export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)" or export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)" or export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" or simply export JAVA_HOME="$(/usr/libexec/java_home)"
Note: If you installed openjdk on mac using brew, run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
for the above to work
Update: added -v flag based on Jilles van Gurp response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With