How to install a specific JDK on Mac OS X?

2020-01-26 13:06发布

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

16条回答
Explosion°爆炸
2楼-- · 2020-01-26 13:27

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)
查看更多
We Are One
3楼-- · 2020-01-26 13:28

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!

查看更多
孤傲高冷的网名
4楼-- · 2020-01-26 13:29

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

查看更多
Luminary・发光体
5楼-- · 2020-01-26 13:34

If you installed brew, cmd below will be helpful:

brew cask install java

查看更多
登录 后发表回答