The cleanest way to manage multiple java versions on Mac is to use Homebrew . And within Homebrew , use: homebrew-cask to install the versions of java. jenv to manage the installed versions of java.
Locate and click on “Extensions” and go to “Preference Panes.” Find Java in the list, select it, and click “Remove.” Now, you've easily removed Java and its extensions from your Mac.
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)
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.
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
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 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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With