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...
I think this other Stack Overflow question could help:
How to get JDK 1.5 on Mac OS X
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.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.
Since most answers are out of date, here's what works as of end of 2018 under the assumption that
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:
[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
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.
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.
This is what happens on a fresh MacBook:
Hopefully this will help out other newbies like me ;)
The easiest way is to use Homebrew. Install Homebrew and then:
You can list all available versions using the following command:
brew cask search java