[ACCEPTED]-How to install a specific JDK on Mac OS X?-installation

Accepted answer
Score: 44

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

export JAVA_HOME=`/usr/libexec/java_home` 

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

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

EDIT:

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

export JAVA_HOME=$(/usr/libexec/java_home)
Score: 20

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

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

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

Score: 10

For people using any LION OS X 10.7.X

They 2 uploaded Java SE 6 version 1.6.0_26 available 1 here

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

Score: 10

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

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

Enter image description here

This 3 is what happens on a fresh MacBook:

Enter image description here

Enter image description here

Hopefully 2 this will help out other newbies like me 1 ;)

Score: 4

The explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library 5 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 4 does not exist. Classes usually located 3 here are instead included in classes.jar. Scripts 2 that rely on the existence of tools.jar 1 need to be rewritten accordingly.

It sucks!

Score: 4

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

brew tap caskroom/versions
brew cask install java7

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

Score: 3

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

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

Score: 3

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

Score: 3

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

Score: 3

If you installed brew, cmd below will be 1 helpful:

brew cask install java

Score: 2

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

e.g.

$sdk list java
$sdk install java <VERSION>
Score: 2

Since most answers are out of date, here's 12 what works as of end of 2018 under the assumption 11 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 10 from one the many available, freely usable 9 OpenJDK editions, e.g.:

Some of these include 8 installers, but if not you can do the following. Assuming 7 here version 11.0.1 for Mac. In your favorite 6 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 5 JDK has significant licensing restrictions allowing you its use basically 4 only for testing, i.e., not for production. If you do not have a support agreement 3 with Oracle, then it seems risky to me to 2 use their JDK, especially since the differences to OpenJDK are minimal.

Edit: added 1 more choices

Score: 2

In the year 2021 you can use just brew

brew install openjdk@11

and you will find your JDK here:

/usr/local/opt/openjdk@11

0

Score: 1

I think this other Stack Overflow question 8 could help:

How to get JDK 1.5 on Mac OS X

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

Score: 1

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

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

The JDK contains a JRE inside 7 it.

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

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

Score: 0

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

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

More Related questions