Java: Finding/Setting JDK/$JAVA_HOME on Mac OS X

As long as I’ve been using a Mac I always understood that if you needed to set $JAVA_HOME for any program.

On my machine this points to the 1.6 JDK:

This was a bit surprising to me since I’ve actually got Java 7 installed on the machine as well so I’d assumed the symlink would have been changed:

Andres and I were looking at something around this yesterday and wanted to set $JAVA_HOME to the location of the 1.7 JDK on the system if it had been installed.

We eventually came across the following article which explains that you can use the /usr/libexec/java_homecommand line tool to do this.

For example, if we want to find where the 1.7 JDK is we could run the following:

And if we want 1.6 the following does the trick:

We can also list all the JVMs installed on the machine:

发布者