Java – Unable to find a $JAVA_HOME at “/usr”, continuing with system-provided Java

ec2-api-toolsjavamacos

The output of any Java command on Mac OS X is prefixed with "Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java…". For example,

$ java -version
Unable to find a $JAVA_HOME at "/usr", continuing with system-provided Java...
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)

Best Answer

The Java home environment variable is set incorrectly, possibly due to instructions from an outdated guide (e.g. EC2 Command Line Tools).

Wherever you set JAVA_HOME (e.g. .bashrc), change it to:

export JAVA_HOME="$(/usr/libexec/java_home)"

As of Mac OS X 10.5, that executable is the supported method of setting JAVA_HOME.

https://developer.apple.com/library/content/qa/qa1170/_index.html

Related Topic