Installing Java on MacOS is not as straightforward as one might hope.
While there are package managers available for MacOS (I recommend
Homebrew) they typically cannot install Java themselves for licensing reasons.
Instead, install Java from an Oracle download:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
MacOS is a UNIX system under the covers and you can of course manually set a JAVA_HOME environment variable and update it as required when you install a new JDK, but there is some system support on update if you instead add this to your
~/.profile
:
export JAVA_HOME=$(/usr/libexec/java_home)
And update your PATH to include:
export PATH=$JAVA_HOME/bin:$PATH
As
java_home
will return the system configured Java version.
You can set this through the Java preferences dialog, go to System Preferences and choose Java. You'll see a dialog that looks something like this:
And one that looks like this:
click the "View..." button to see runtimes
runtimes are listed here
Other Notes
If you have multiple Java versions installed you can use the -v 1.x parameter to select a particular version of Java. So for example if you often have to use Java 6 for backwards compatibility:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
To see all installed Java versions run:
/usr/libexec/java_home -V
A separate 'tap' for homebrew may allow installation of Java now, albeit with a bit more preparatory setup, see:
http://hanxue-it.blogspot.ch/2014/05/installing-java-8-managing-multiple.html