Don't rely on Oracle to install Java properly on your Mac.
Use Homebrew. this will install the latest jdk:
brew cask install java
in my case, jdk is openjdk 11.
If you want to manage multiple versions of Java on your Mac, consider using jenv.
UPDATE: Now that Java 8 is no longer the most current version, if you want java 8 install it this way:
brew tap caskroom/versions
brew cask install java8
To get a list of all older versions of java: brew tap caskroom/versions
and then use brew search java
.
We use brew cask since we'd otherwise use the Oracle GUI installer that will likely not install Java properly on your Mac. (Use brew cask install APP to install GUI apps; use brew install APP.) Java is not a GUI app; It should not require "cask" but at least Oracle is consistent.
If you want to install jdk7, you need to download jdk on oracle website(requires a login). Then install it.
mac default install jdk7 to /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk
jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable.
Linux / OS X
$ git clone https://github.com/gcuisinier/jenv.git ~/.jenv
Mac OS X via Homebrew
$ brew install jenv
Installation
Bash
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
Zsh
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc
Configure
$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
oracle64-1.6.0.39 added
$ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home
oracle64-1.7.0.11 added
And Use !
List managed JDKs
$ jenv versions
system
oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)
Configure global version
$ jenv global oracle64-1.6.0.39
Configure local version (per directory)
$ jenv local oracle64-1.6.0.39
Configure shell instance version
$ jenv shell oracle64-1.6.0.39
view JAVA_HOME
$ jenv exec bash
bash-3.2$ echo $JAVA_HOME
ps: when install Java, do not use a proxy, because the download speed is faster and do success.
reference address:
1. https://stackoverflow.com/questions/24342886/how-to-install-java-8-on-mac
3. http://davidcai.github.io/blog/posts/install-multiple-jdk-on-mac/