Java – How to install a specific JDK on Mac OS X

installationjavamacos

I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp.
I looked for a Mac version, but I'm a bit surprised to only see downloadable versions for Linux, Windows and Solaris

Here's the message for Mac:

"Apple Computer supplies their own version of Java. Use the Software
Update feature (available on the Apple menu) to check that you have
the most up-to-date version of Java for your Mac."

OK BUT… when I update Java with Mac I have a JRE and not a JDK…

I don't understand why a JDK version doesn't exist that is easily downloadable/installable (like a jar to unzip?) for Mac…

Best Answer

In a comment under @Thilo's answer, @mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:

export JAVA_HOME=`/usr/libexec/java_home` 

This will dynamically assign to JAVA_HOME the location of the first JDK listed in the "General" tab of "Java Preferences" utility.

See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html

EDIT:

If you prefer parentheses to backticks for command substitution, this also works:

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