JAVA_HOME setting on MacOS
I just downloaded the latest Java Update 1.7.09 for MacOS and installed it. And as usual, I had to fix the JAVA_HOME
environmental property, so that all my Maven etc. tools still worked properly. In ~/.bash_profile
, I added/updated following entries:
I use JAVA_HOME6
and JAVA_HOME7
so that I can easily switch the standard Java version.
But, stop, stop, there must be a better way to do that, so that I don't have to update
these lines after every Java download. And actually it is by using the
not-so-well-known-but-very-useful command java_home
:
The java_home command returns a path suitable for setting the JAVA_HOME environment variable. It determines this path from the user's enabled and preferred JVMs in the Java Preferences application. Additional constraints may be provided to filter the list of JVMs available. [...] The path is printed to standard output.
On my machine, java_home
prints following path to the STDOUT
:
So, I can change my .bash_profile
as follows:
On my machine, my Java environmental parameters becomes:
Finito.
Original post: http://peter-on-java.blogspot.com/2012/10/javahome-setting-on-macos.html