How to Install Java 8 on Mac
Editors Note: This Question Was Asked in 2014, and the Answers May Be Outdated. I Want to Do Some Programming with the Latest Javafx, Which Requires Java 8...
Editors note: This question was asked in 2014, and the answers may be outdated.
I want to do some programming with the latest JavaFX, which requires Java 8. I'm using IntelliJ 13 CE and Mac OS X 9 Mavericks. I ran Oracle's Java 8 installer, and the files look like they ended up at
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk
but previous versions are at
/System/Library/Java/JavaFrameworks/jdk1.6....
Not sure why the latest installer puts this in /Library instead of /System/Library (nor what the difference is). But /usr/libexec/java_home doesn't find 1.8, so all the posts I've found on how to set your current java version don't work. I've tried adding a symbolic link to make it look like 1.8 is in the /System/Library... path, but it doesn't help. /usr/libexec/java_home -V still only lists the old Java 1.6.
Ironically, the "Java" control panel under System Preferences shows only Java 1.8!
Why doesn't Oracle's installer put it where it really goes? And how can I work around this problem?
33 Answers
Oracle has a poor record for making it easy to install and configure Java, but using Homebrew, the latest OpenJDK (Java 14) can be installed with:
brew install --cask adoptopenjdk8
For the many use cases depending on an older version (commonly Java 8), the AdoptOpenJDK project makes it possible with an extra step.
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8
Existing users of Homebrew may encounter Error: Cask adoptopenjdk8 exists in multiple taps due to prior workarounds with different instructions. This can be solved by fully specifying the location with brew install --cask adoptopenjdk/openjdk/adoptopenjdk8.
Note: Oracle Java 8/9/10 is no longer available for public download (license change).
First install and update brew from Terminal:
bash -c "$(curl -fsSL )"
brew tap homebrew/cask-versions
brew update
NEW as of June 2019
To install the JDKs from AdoptOpenJDK:
brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8
brew install --cask adoptopenjdk9
brew install --cask adoptopenjdk10
brew install --cask adoptopenjdk11
OLD
Java 8:
brew install --cask java8
Java Latest:
brew install --cask java
Java8 is no longer available on homebrew, brew install java8 will not work.
Instead, use:
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
See this commit for technical details.
Please note as well you may see issues around Cask adoptopenjdk8 exists in multiple taps. This is a known issue, currently being worked on, which you can see here:
For those who don't want to run through the details, here is a summary:
# To install JDK8
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
# To be able to safely run 'brew cleanup'
brew untap adoptopenjdk/openjdk
brew untap caskroom/versions
brew cleanup
I just did this on my MBP, and had to use
$ brew tap homebrew/cask-versions
$ brew cask install java8
in order to get java8 to install.
In 2022, you can use just brew
brew install openjdk@8
and maybe you need to update PATH env:
export PATH="/usr/local/opt/openjdk@8/bin:$PATH"
Must Read
…for the future give a try to sdkman, is better than brew
curl -s "" | bash
then open a new shell and try list to see what you could install ;-)
sdk list java
At time of writing to install java 8 you could use:
sdk install java 8.0.322-tem
NOTE: Update the install command to match some existing Identifier show from running sdk list java
Assumption: Mac machine and you already have installed homebrew.
Install cask (with Homebrew 0.9.5 or higher, cask is included so skip this step):
$ brew tap caskroom/cask
$ brew tap caskroom/versions
To install latest java:
$ brew cask install java
To install java 8:
$ brew cask install adoptopenjdk/openjdk/adoptopenjdk8
If you want to install/manage multiple version then you can use 'jenv':
Install and configure jenv:
$ brew install jenv
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
Add the installed java to jenv:
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.11.0_2.jdk/Contents/Home
To see all the installed java:
$ jenv versions
Above command will give the list of installed java:
* system (set by /Users/lyncean/.jenv/version)
1.8
1.8.0.202-ea
oracle64-1.8.0.202-ea
Configure the java version which you want to use:
$ jenv global oracle64-1.6.0.39
To set JAVA_HOME:
$ jenv enable-plugin export
An option that I am starting to really like for running applications on my local computer is to use Docker. You can simply run your application within the official JDK container - meaning that you don't have to worry about getting everything set up on your local machine (or worry about running multiple different versions of the JDK for different apps etc)
Although this might not help you with your current installation issues, it is a solution which means you can side-step the minefield of issues related with trying to get Java running correctly on your dev machine!
The benefits are:
- No need to set up any version of Java on your local machine (you'll just run Java within a container which you pull from Docker Hub)
- Very easy to switch to different versions of Java by simply changing the tag on the container.
- Project dependencies are installed within the container - so if you mess up your config you can simply nuke the container and start again.
A very simple example:
Create a Dockerfile:
FROM java:8
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
- Here we are specifying the Java container running version 8 of the SDK (
java:8- to use Java 7, you could just specify:java:7) - We are mapping the local directory with the directory:
/usr/src/myappinside the container
Create a docker-compose.yml file:
version: "2"
services:
java:
build: .
volumes:
- .:/usr/src/myapp
Now, assume we have this Java file:
HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
So we have the following file structure:
.
|_ Dockerfile
|_ docker-compose.yml
|_ HelloWorld.java
You can do various Java things like:
compile:
docker-compose run --rm java javac HelloWorld.java
- You should note that the HelloWorld.class shows up in your current directory (this is cause we've mapped the current directory to the location inside the container where our code exists
run:
docker-compose run --rm java java HelloWorld
- Note: the first time you run this it will fetch the image etc. This will take a while - it only happens the first time
docker-compose run- runs a command from within the container-rmtells docker to remove the container once the command is finished runningjavais the name of the service/container (from our docker-compose file) against which this command will run- the rest of the line is the command to run inside the container.
This is quite a cool way of dealing with running different versions of Java for different apps without making a complete mess of your local setup :).
Here is a slightly more complex example which has Maven and a simple Spring app
Disclaimer:
- I haven't really tried this within an IDE like IntelliJ - so not entirely sure how that aspect of things would work. Though it looks like docker support is coming
- Here is a significantly more complex example running Microservices with Spring Boot, Zuul and Docker
tl;dr
/Library/Java/JavaVirtualMachines/ is the correct location for the JVM to be installed. This has been the case for several years now. Many years ago, other locations were used, but no longer.
You have a choice of several vendors to obtain an installer app to install a Java implementation on your Mac. Download an installer to run locally and then discard, as you commonly do for many apps.
Your Question mentions JavaFX/OpenJFX. You might find it convenient to use a Java implementation that comes bundled with the OpenJFX libraries, such as LibericaFX from BellSoft or ZuluFX from Azul Systems.
Use the Installer, Luke
Other answers suggesting the Homebrew package manager seem a bit extreme to me. I am sure Homebrew has some good uses. But to simply run Java, or do Java programming, installing Homebrew is a needless extra step. Installing Homebrew (package manager) for the single goal of obtaining Java is like building a landing strip to park your car instead of using your driveway. If you already have it, fine, use it. But suggesting Homebrew to those who simply need Java is poor advice.
People not already using Home-brew can simply download a Mac installer from a trusted source.
You have multiple sources to obtain an easy-to-use installer app to put Java on your Mac. Run the installer on your Mac just as you do for many other apps.
Here is a flowchart diagram for finding a source of Java 11, some of which also offer Java 8.
Download an installer from a vendor such as Adoptium(AdoptOpenJDK.net).
Run the installer.
JavaVirtualMachines folder is now correct
Why doesn't Oracle's installer put it where it really goes? And how can I work around this problem?
Not a problem.
The folder /Library/Java/JavaVirtualMachines/ is the new home for JVMs on macOS.
To install a JVM, use an installer, discussed below.
To uninstall, simply use the Finder to delete a JVM from that folder. You will be prompted for system admin password to complete the removal.
Java 9 & 10 & 11
Back in 2010, Apple joined the OpenJDK project, along with Oracle, IBM, Red Hat, Azul, and other Java vendors. Each member contributes source code, testing, and feedback to the unified OpenJDK codebase.
Apple contributed most of its Mac-specific code for its JVM. Now Apple no longer releases its own Mac-specific JVM. You now have your choice of JVM supplier, with builds coming from the OpenJDK codebase.
You will find source code at:
New release cadence
Be aware that in 2017, Oracle, the JCP, and OpenJDK have adopted a new rapid “release train” plan for regularly-scheduled versions of Java to be delivered in a predictable manner.
Read this 2018-07 Azul Systems blog post for many details, Eliminating Java Update Confusion by Simon Ritter.
Also read Java Is Still Free.