How to install a specific JDK on Mac OS X?

JavaMacosInstallation

Java Problem Overview


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...

Java Solutions


Solution 1 - Java

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)

Solution 2 - Java

As the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).

See: http://developer.apple.com/java/

NOTE This answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download page on Oracle's website now.

Solution 3 - Java

For people using any LION OS X 10.7.X

They uploaded Java SE 6 version 1.6.0_26 available here

http://support.apple.com/kb/dl1421

Solution 4 - Java

I bought a MacBook Pro yesterday (Mac OS X v10.8 (Mountain Lion)) and there is no JDK installed by default...

As well as javac, I also found it didn't have packages such as SVN installed. It turns out you can get everything from the Apple developer page (you will need to register with your AppleID). SVN is part of the "Command Line Tools" package.

Enter image description here

This is what happens on a fresh MacBook:

Enter image description here

Enter image description here

Hopefully this will help out other newbies like me ;)

Solution 5 - Java

The explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library and Mac's JDK doesn't provide it:

(Cf. http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html)

> tools.jar does not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jar need to be rewritten accordingly.

It sucks!

Solution 6 - Java

The easiest way is to use Homebrew. Install Homebrew and then:

brew tap caskroom/versions
brew cask install java7

You can list all available versions using the following command: brew cask search java

Solution 7 - Java

Solution 8 - Java

As of Mac OS X v10.6 (Snow Leopard), you can run Java 6 in 32-bit mode on either 32-bit or 64-bit Intel processor equipped Macs.

If you cannot upgrade to Snow Leopard, [Soy Latte][3] is a pre-compiled version of Java 6 for Intel 32-bit.

[3]: http://landonf.bikemonkey.org/static/soylatte/ "Soy Latte"

Solution 9 - Java

Compiling with -source 1.5 -target 1.5 (in a JDK 6 environment) will honor only language elements that were in 1.5 and prior. Great. But there were no language changes in 6 anyway. Problem with this approach (on Mac with 1.6) is that using classes that came AFTER 1.5 will still compile because they exist in the rt.jar. So one could run in a 1.5 env and get a class not found exception with no prior warning when compiling. I found this out the hard way with javax.swing.event.RowSorterEvent/Listener. Both entered "Since 1.6" but are not caught with -source 1.5

Solution 10 - Java

There are various tricky issues with having multiple versions of Java (Apple's own Java 6 and Oracle JDK 7 or even 8) on one's Mac OS X system, and using different versions for different applications. I spent some time writing up my experience of my experience of installing and configuring various versions of JDK on Mac OS X 10.9.2.

Solution 11 - Java

If you installed brew, cmd below will be helpful:

>brew cask install java

Solution 12 - Java

Check this awesome tool sdkman to manage your jdk and other jdk related tools with great ease!

e.g.

$sdk list java
$sdk install java <VERSION>

Solution 13 - Java

Since most answers are out of date, here's what works as of end of 2018 under the assumption that

  1. You want to install the GPL version of OpenJDK.[0]
  2. You do not want to install Homebrew

In that case, grab the desired version from one the many available, freely usable OpenJDK editions, e.g.:

Some of these include installers, but if not you can do the following. Assuming here version 11.0.1 for Mac. In your favorite shell, run:

tar -xzf openjdk-11.0.1_osx-x64_bin.tar.gz
sudo mv jdk-11.0.1.jdk /Library/Java/JavaVirtualMachines
# Fix owner and group
sudo chown -R root:wheel /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
# (Optional) Check if the new JDK can be found
/usr/libexec/java_home
=> /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home

[0] Note that the Oracle branded JDK has significant licensing restrictions allowing you its use basically only for testing, i.e., not for production. If you do not have a support agreement with Oracle, then it seems risky to me to use their JDK, especially since the differences to OpenJDK are minimal.

Edit: added more choices

Solution 14 - Java

In 2022, give a try to sdkman, is better than brew

curl -s "https://get.sdkman.io" | bash

then open a new shell and try list to see what you could install ;-)

sdk list java 

At time of writing you could use:

sdk install java 17.0.1-tem

Solution 15 - Java

I think this other Stack Overflow question could help:

https://stackoverflow.com/questions/2846573/how-to-get-jdk-1-5-on-mac-osx

It basically says that if you need to compile or execute a Java application with an older version of the JDK (for example 1.4 or 1.5), you can do it using the 1.6 because it is backwards compatible. To do it so you will need to add the parameter -source 1.5 and/or -target 1.5 in the javac options or in your IDE.

Solution 16 - Java

JDK is the Java Development Kit (used to develop Java software).

JRE is the Java Runtime Environment (used to run any .jar file 'Java software').

The JDK contains a JRE inside it.

On Windows when you update Java, it updates the JRE automatically.

On Mac you do not have a JRE separated you have it, but inside the JDK, so when you update Java it will update your JRE which is inside your JDK; it doesn't install an JDK for you. You need to get it from somewhere else.

Solution 17 - Java

As a rule you cannot install other versions of Java on a Mac than those provided by Apple through Software Update. If you need Java 6 you must have a 64-bit Intel computer. You should always have Java 5 and 1.4 and perhaps 1.3 installed if you have at least OS X 10.4.

If you have VERY much elbow grease and is willing to work with beta software you can install the OpenJDK under OS X, but I don't think you want to go there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionajeansonView Question on Stackoverflow
Solution 1 - JavaMark TyeView Answer on Stackoverflow
Solution 2 - JavaJesperView Answer on Stackoverflow
Solution 3 - JavaRoy CalderonView Answer on Stackoverflow
Solution 4 - Javamatt burnsView Answer on Stackoverflow
Solution 5 - JavaajeansonView Answer on Stackoverflow
Solution 6 - JavasolomkinmvView Answer on Stackoverflow
Solution 7 - JavapedromarceView Answer on Stackoverflow
Solution 8 - JavaBrian M. CarrView Answer on Stackoverflow
Solution 9 - JavaEvanView Answer on Stackoverflow
Solution 10 - JavaMeng LuView Answer on Stackoverflow
Solution 11 - JavaPonderousView Answer on Stackoverflow
Solution 12 - JavaRishikesh DarandaleView Answer on Stackoverflow
Solution 13 - JavaLCCView Answer on Stackoverflow
Solution 14 - JavafreedevView Answer on Stackoverflow
Solution 15 - JavaFgblanchView Answer on Stackoverflow
Solution 16 - Javauser1477929View Answer on Stackoverflow
Solution 17 - JavaThorbjørn Ravn AndersenView Answer on Stackoverflow