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.
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.
For OS X you can do:
This answer is related to Mountain Lion and not Lion. I needed to do this for the AWS Command Line Tools. According to the AWS docs, running
which java
returns/usr/bin/java
.So, I set
JAVA_HOME=/usr
in my.bashrc
.Apparently,
/usr/bin/java
is a symbolic link to/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
which makes it all work.Update
As mentioned in the comment below, this
JAVA_HOME
value is not an ideal solution when theJAVA_HOME
environment variable is to be used by things other than the AWS Command Line Tools. It works fine for the AWS Command Line Tools, though, as given in their docs.Newer Oracle JVMs such as 1.7.0_21-b12 seem to install here:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
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.
Update: added -v flag based on Jilles van Gurp response.
/usr/libexec/java_home
is not a directory but an executable. It outputs the currently configured JAVA_HOME and doesn't actually change it. That's what the Java Preferences app is for, which in my case seems broken and doesn't actually change the JVM correctly. It does list the 1.7 JVM but I can toggle/untoggle & drag and drop all I want there without actually changing the output of/usr/libexec/java_home
.Even after installing 1.7.0 u6 from Oracle on Lion and setting it as the default in the preferences, it still returned the apple 1.6 java home. The only fix that actually works for me is setting JAVA_HOME manually:
At least this way when run from the command line it will use 1.7.
/usr/libexec/java_home
still insists on 1.6.Update: Understanding Java From Command Line on OSX has a better explanation on how this works.
is the way to do it. Note, updating this to 1.8 works just fine.
A better (more upgradable) way is to use the following:
This should work with AWS also since it has
bin
underneath Home