1139

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?

Thorbjørn Ravn Andersen
  • 68,906
  • 28
  • 171
  • 323
user3763100
  • 11,688
  • 3
  • 10
  • 7
  • 11
    It "really goes" where it ended up -- `/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/`. The previous one was where the Apple-provided Java versions went, and as Apple doesn't provide Java any more the install location has changed. – awksp Jun 21 '14 at 17:49
  • Similar: [*How to use jdk without jre in Java 11*](https://stackoverflow.com/q/52584888/642706) – Basil Bourque Jun 19 '20 at 01:27

28 Answers28

2102

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.

Palash Goel
  • 576
  • 5
  • 14
l3x
  • 27,652
  • 1
  • 45
  • 35
  • 2
    I had to run this multiple times before the the dmg would download from oracle, each time it continued at the last point it left off. – James Oct 08 '15 at 22:19
  • @James - was probably a network issue. +1 for mentioning jenv – Benjineer Nov 25 '15 at 02:48
  • 96
    As of December 2015, it is now unnecessary to install cask manually as it is now part of homebrew's installation. So after updating homebrew via `brew update`, you are set to use `brew cask`. – davetw12 Dec 16 '15 at 17:22
  • 73
    Thanks, it's amazing how horrible the Java installation process using the "official" links/docs are. – enderland Feb 15 '16 at 22:31
  • 1
    @l3x - I suggested an edit that would update your answer to what davetw12 said. It was rejected because reviewers felt it was too different from your answer. Would you be willing to make your answer a shared answer so we can make this right and current? Or otherwise accept the edit? – BitwiseMan May 23 '16 at 19:40
  • 16
    @tandrewnichols I just ran `brew cask install java` on my El Capitan Mac and it's downloading `jdk-8u112-macosx-x64.dmg`. – Calrion Oct 24 '16 at 00:43
  • If having anymore issue with JRE or JDK try https://gist.github.com/johan/10590467 – AKFourSeven Jan 24 '17 at 10:25
  • 9
    it DOES install JDK. `brew cask info java` – cambunctious Mar 26 '17 at 00:27
  • 3
    In contrast to @tandrewnichols I found this procedure installed JDK as well as the runtime - so full Java support. – Rich Apodaca Mar 29 '17 at 18:39
  • 2
    If you installed java using the Oracle updater and want Homebrew to manage it, do I have to fully uninstall the Oracle Java first? – Rolando May 31 '17 at 05:05
  • ```brew cask install java``` installed jdk ftw – killscreen Jul 05 '17 at 19:09
  • 12
    Note that as of October 2017, the default brew command (as well as most of those in the comments) will install whatever is the *latest* major version JDK (i.e. java 9) rather than a specific older one (for example, Java 8 as in the OP). See this helpful blog post for a description of how to use brew to install an earlier version of Java if needed. http://www.lonecpluspluscoder.com/2017/10/08/installing-other-versions-of-the-java-jdk-via-homebrew/ – shiri Oct 09 '17 at 09:24
  • What is cask significance here ? – Sindhu Oct 18 '17 at 17:46
  • 9
    In case others missed this, the `brew cask install java8` approach installs `java` in `/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/bin/java`. – danvk Feb 26 '18 at 16:24
  • 2
    3/28/18 - try: brew install caskroom/version/java8 – Jim Ford Mar 28 '18 at 16:40
  • 54
    `Error: Cask 'java8' is unavailable: No Cask with this name exists.` – Elderry Aug 16 '18 at 09:01
  • 1
    I had to use the following commands `brew tap homebrew/cask-versions; brew cask install java8` – mark Dec 19 '18 at 18:58
  • What happens if I install java via brew, and java was already installed from some other method? Will brew handle this ok? Or do I need to explicitly uninstall first? – James Wierzba Feb 08 '19 at 21:14
  • 2
    `brew cask install java8` Error: Cask java8 exists in multiple taps: – WeiChing 林煒清 Feb 22 '19 at 05:28
  • 1
    @danvk I install brew under ~/homebrew and hope the java can be installed under the ~/homebrew/bin, just like other apps, do you think it's possible and how to do that? – kitaev Mar 04 '19 at 20:26
  • 4
    This doesn't work anymore, see [here](https://github.com/Homebrew/homebrew-cask-versions/issues/7253) for more details. – Sean Breckenridge Apr 17 '19 at 21:24
  • @WeiChingLin you can fix that by specifying which tap you want to install from. e.g. `brew cask install caskroom/versions/java8` or `brew cask install homebrew/cask-versions/java8`. However, that wont work currently since oracle is phasing out their java8 download. See [here](https://github.com/Homebrew/homebrew-cask-versions/issues/7253) for more details. – Sean Breckenridge Apr 17 '19 at 23:32
  • 97
    The workaround for now is to `brew tap homebrew/cask-versions` and use `brew cask install homebrew/cask-versions/adoptopenjdk8` – Sean Breckenridge Apr 19 '19 at 21:31
  • 4
    It is not possible to install Java8 using Brew anymore because of Oracle license changes. Java8 is not public anymore for download. – Marcelo Xavier Apr 24 '19 at 13:05
  • See [this answer below](https://stackoverflow.com/a/55774255/9348376) for further details. – Sean Breckenridge May 14 '19 at 15:45
  • 3
    Java8 is not available for brew / cask anymore: https://github.com/Homebrew/homebrew-cask-versions/issues/7253 – Adam Matan May 22 '19 at 11:40
  • 9
    `Cask 'java8' is unavailable: No Cask with this name exists.` – user924 Jun 09 '19 at 15:30
  • Why not rely on the Oracle installer? Has worked for me so far. – Thorbjørn Ravn Andersen Jul 27 '19 at 10:22
  • Great advice to install jenv, makes it a lot easier to manage several versions of java. I am always wary of zapping anything installed into macOS by Apple, and with jenv, you can keep everything nicely separated. – mok0 Aug 07 '19 at 08:56
  • 1
    Latest workaround requires `brew tap adoptopenjdk/openjdk` followed by `brew cask install adoptopenjdk8`. That may fail with "Error: Cask adoptopenjdk8 exists in multiple taps" because you already attempted this another way, so specify exact location with `brew cask install adoptopenjdk/openjdk/adoptopenjdk8` – Josh Klein Nov 16 '19 at 02:23
  • Ran these commands, but the wrong version of openjdk is on my machine: ```java --version``` ```openjdk 12.0.1 2019-04-16 OpenJDK Runtime Environment (build 12.0.1+12) OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)``` – Code Wiget Dec 21 '19 at 03:13
  • If you have multiple versions of open jdk installed and want to change default version: `/usr/libexec/java_home -V` and then `export JAVA_HOME='usr/libexec/java_home -v 1.8.0_232'` used example version – Rakesh Patil Jan 08 '20 at 17:11
  • On reinstall I had to enter my password 300 times for it to reinstall properly - I guess I needed to give permission to overwrite a bunch of existing files. – tschumann Jan 20 '20 at 01:24
  • 3
    `brew cask remove java; brew cask install adoptopenjdk8; java -version` – kenorb Feb 14 '20 at 16:23
  • `openJDK` does not contain JavaFX – wasserholz May 07 '20 at 12:21
  • the position of this answer should be higher – tokyodrift1993 Jul 01 '20 at 05:33
  • After following these steps, you may still need to define JAVA_HOME so it points to the brew installed java8. What worked for me was `export JAVA_HOME=$(/usr/libexec/java_home -v1.8)` – AndyP Feb 10 '21 at 10:19
  • How to install specific build of AdoptOpenJdk8 – eatSleepCode May 25 '21 at 14:31
801

Note: Oracle Java 8/9/10 is no longer available for public download (license change).

First install and update brew from Terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

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
vivek yadav
  • 665
  • 7
  • 12
kavehmb
  • 9,040
  • 1
  • 15
  • 22
  • 3
    Interesting to note that this did not work for me on Mavericks, so it did not answer the OP's question, but it did work for me on Captain, so it was useful as an answer.. – Tommy Oct 14 '15 at 14:19
  • 1
    For me, in El Kapitan, it would only download a few extra percent each time I ran it, so I ran it in a loop (in fish shell) and it eventually worked. `while math "$status == 1"; brew install Caskroom/cask/java; end` – philwhln Nov 30 '15 at 18:15
  • This works, but I did have to `brew install Caskroom/cask/java` many times because the transfer kept closing: `curl: (18) transfer closed with 34724700 bytes remaining to read` – eddywashere Dec 04 '15 at 19:38
  • 1
    Didn't work for me on Yosemite (OSX v10.10.5). I get `Error: Cask 'java' definition is invalid: Bad header line: parse failed` ... Seems like this works only for El Capitan and not for any version preceding version of OSX (Yosemite, Mavericks..., ) – James Lawson Jan 05 '16 at 09:49
  • 1
    I'm also getting the parse failed error, and I'm on El Capitan. Has anyone else encountered this and/or found a solution? – lewiguez Jan 06 '16 at 16:31
  • Oracle official site is giving weired errors, this is life savior – Pradeep Feb 22 '16 at 21:55
  • 3
    I installed homebrew fresh on a new OS X El Capitan machine and didn't have to run the `brew tap` command in the answer above. The first and third commands were sufficient. – Adil Hussain Apr 14 '16 at 12:51
  • 1
    brew cask install caskroom/versions/java8 – Arun Mar 03 '18 at 21:56
  • 1
    Works on 10.8 after apple `git` is replaced with homebrew `git`. :) Very nice. – tresf Mar 15 '18 at 00:44
  • 1
    Anyone wanting Java 7: java7 is not available in cask versions, but zulu7 appears to work instead. https://github.com/Homebrew/homebrew-cask/issues/9447 – comfytoday May 27 '18 at 23:38
  • 1
    Error: Cask 'java8' is unavailable: No Cask with this name exists. – Min2 Jun 20 '18 at 17:18
  • Use `brew tap caskroom/versions` before to avoid this errors. @Min2 – Felipe Augusto Sep 27 '18 at 20:13
  • On Mac OSX Sierra `brew cask install caskroom/versions/java8` – Shikhar Mishra Dec 02 '18 at 05:38
  • `curl: (22) The requested URL returned error: 404 Not Found Error: Download failed on Cask 'java8' with message: Download failed: https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-macosx-x64.dmg` – chovy Jan 15 '19 at 18:01
  • 16
    `Error: Cask 'java8' is unavailable: No Cask with this name exists.` – user924 Jun 09 '19 at 15:35
  • This worked perfectly in Aug 2019. Steps: 1. `brew tap adoptopenjdk/openjdk` 2. `brew cask installadoptopenjdk/openjdk/adoptopenjdk8` – Aditya Purandare Aug 02 '19 at 21:57
  • 7
    `$ brew cask install adoptopenjdk8 Error: Cask adoptopenjdk8 exists in multiple taps: caskroom/versions/adoptopenjdk8 adoptopenjdk/openjdk/adoptopenjdk8` . I have to use `brew cask install adoptopenjdk/openjdk/adoptopenjdk8` – roottraveller Aug 26 '19 at 12:01
  • just to follow from @roottraveller previous comment. It appears as though the adoptopenjdk versions are now in the caskroom/versions tap as well. So you could just do brew `tap caskroom/versions` and `brew cask install adoptopenjdk8`, skipping the adoptopenjdk tap. Might be useful if you've already tapped and updated caskroom/versions. – rod Aug 28 '19 at 05:01
  • 5
    `brew tap homebrew/cask-versions` and `brew cask install adoptopenjdk8` works for me on Hi Sierra 10.13.6 – xjlin0 Oct 05 '19 at 14:30
  • Thank you for this. This also solves the error in Catalina " Java for macOS 2017-001 can’t be installed on a disk. A newer version of this package is already installed.". – theteddyboy Oct 21 '19 at 08:52
  • @kavehmb Is there way to install it so without Sudo? Using above methods, it's trying to use `usr/local/` space, even when I specified `--appdir=~/Applications`? – GensaGames Oct 22 '19 at 21:46
  • 1
    how do i set the JAVA_HOME path for the openjdk8?? – Wijay Sharma Nov 19 '19 at 18:07
  • As @ kavehmb says, 1.$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $brew tap homebrew/cask-versions $brew update $brew tap adoptopenjdk/openjdk $brew cask install homebrew/cask-versions/adoptopenjdk8 (Or brew cask install adoptopenjdk/openjdk/adoptopenjdk8) That works for me on macOS 10.12.6 Sierra. – McAllister Bowman Dec 14 '19 at 07:54
  • Adding this for people using newer mac versions Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" – Enihr Sep 30 '20 at 11:34
  • I believe the first command (to install "the latest OpenJDK") be `brew install --cask adoptopenjdk` and not `brew install --cask adoptopenjdk8` which will install JSK 8 not latest? also the latest is now 15 (as of Sep 2020). Also, Iit may help others to include `brew tap adoptopenjdk/openjdk` *before* the first command, as folks trying the install w/o the tap are getting errors. – djb Feb 02 '21 at 22:36
155

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:

https://github.com/AdoptOpenJDK/homebrew-openjdk/issues/106

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
Dave Kerr
  • 4,419
  • 2
  • 24
  • 28
130

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.

Petrus Theron
  • 25,051
  • 30
  • 137
  • 263
Jain Waldrip
  • 1,430
  • 1
  • 7
  • 6
76

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
rmtmckenzie
  • 26,401
  • 5
  • 82
  • 83
Lyncean Patel
  • 1,623
  • 11
  • 8
  • 3
    Best solution! Thank you! – viktorianer Feb 04 '20 at 14:48
  • Thank you. Starts with short and to the point solution and continues with another useful tool: 'jenv' is handy to have around and is missing from most other answers. Helped with packaging Scala (2.12/2.13) code in 2020. – emllnd Apr 22 '20 at 07:47
  • Works like a charm, brew cask install adoptopenjdk/openjdk/adoptopenjdk8 – jeadonara May 16 '20 at 14:35
  • This is the best answer indeed! Ideal for folks (like me) who have and need to manage multiple versions of java – Ankit Khettry Sep 04 '20 at 11:09
69

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:

  1. 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)
  2. Very easy to switch to different versions of Java by simply changing the tag on the container.
  3. 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/myapp inside 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
  • -rm tells docker to remove the container once the command is finished running
  • java is 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:

toast38coza
  • 7,175
  • 2
  • 36
  • 31
  • 3
    Good example using Docker, not sure why you got a downvote before. – Andrew Apr 28 '16 at 14:25
  • 32
    I'd imagine the downvote because this does not answer the question of running Java on OS X/MacOS. Answering "How do I do this on platform X" with "Just use a VM/shim to do it on platform Y" is not productive. – whitfin Dec 14 '16 at 22:18
  • 1
    especially for native java development (e.g. using SWIG, JNI and LIBRARY_PATH) – Mizux Apr 15 '19 at 09:23
25

I'm having the same problem to solve, because I need to install JDK8 to run Android SDK Manager (because it seems that don't work well with JDK9). However, I tell you how I solve all problems on a Mac (Sierra).

First, you need brew with cask and jenv.

  1. You can find an useful guide here,Homebrew Cask Installation Guide. Remember to tap 'caskroom/versions' running in the terminal: brew tap caskroom/versions
  2. After that, install jenv with: brew install jenv
  3. Install whatever version you want with cask brew cask install java8 (or java7 or java if you want to install the latest version, jdk9)
  4. The last step is to configure which version to run (and let jenv to manage your JAVA_HOME) jenv versions to list all versions installed on your machine and then activate the one you want with jenv global [JDK_NAME_OF_LIST]

You could find other useful informations here on this Github Gist brew-java-and-jenv.md, on this blog Install multiple JDK on a Mac and on Jenv Website

25

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.

Flowchart guiding you in choosing a vendor for a Java 11 implementation

Download an installer from a vendor such as Adoptium(AdoptOpenJDK.net).

Download page at AdoptOpenJDK.net

Run the installer.

screenshot of installer running

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.

screenshot of the folder "/Library/Java/JavaVirtualMachines/" in the Finder

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: http://openjdk.java.net

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.

Vendors

For a rather exhaustive list of past and present JVM implementations, see this page at Wikipedia.

Here is a discussion of a few vendors. See the flowchart above for more vendors

Oracle JDK

Oracle provides JDK and JRE installers for multiple platforms including macOS.

Over the years since acquiring Sun, Oracle has combined the best parts of the two JVM engines, HotSpot and JRocket, and merged them into the OpenJDK project used as the basis for their own branded implementations of Java.

Their new business plan, as of 2018, is to provide a Oracle-branded implementation of Java for a fee in production, and at no cost for use in development/testing/demo. Support for previous releases requires a paid support program. They have declared their intention for their branded release to be at feature-parity with the OpenJDK release. They have even donated their commercial add-ons such as Flight Recorder to the OpenJDK project.

Oracle also releases a build of OpenJDK with no support: http://jdk.java.net/

Oracle has produced a special purpose JDK, GraalVM.

Zulu & Zing by Azul

Azul Systems provides a variety of JVM products.

  • Their Zulu line is based directly on OpenJDK, and is available at no cost with optional paid support plans.
  • Their Zing line offers commercial JVM products enhanced with alternate technical implementations such as a specialized garbage-collector.

Both of their lines offer installers for macOS.

I am currently use Zulu for Java 10.0.1 on macOS High Sierra with IntelliJ 2018.2 and Vaadin 8. I downloaded from this page. By the way, I do not find any Java-related items installed on the Apple System Preferences app.

Adoptium

Adoptium, formerly known as AdoptOpenJDK, is a community-led effort to build binaries of the OpenJDK source. Many of the other vendors of Java implementations support this work at Adoptium.

  • Your choice of either HotSpot or OpenJ9 engine.
  • Builds available for macOS, Linux, and Windows, and other platforms.

OpenJ9 by Eclipse

The OpenJ9 project is an another implementation of the JVM engine, an alternative to HotSpot.

Now sponsored at the Eclipse Foundation, with technology and backing donated by IBM in 2017.

For prebuilt binaries, they refer you to the AdoptOpenJDK project mentioned above.

Motivations in choosing a vendor for Java


How to install

The installers provided by Oracle or by Azul are both utterly simple to operate. Just run the installer app on your Mac. A window appears to indicate the progress of the installation.

When completed, verify your JVM installation by:

  • Visiting the /Library/Java/JavaVirtualMachines/ folder to see an item for the new JVM.
  • Running a console such as Terminal.app and type java -version to see the brand and version number of your JVM.

After verifying success, dismount the .dmg image in the Finder. Then trash the .dmg file you downloaded.

Basil Bourque
  • 218,480
  • 72
  • 657
  • 915
  • 6
    This answer is odious. Just use brew cask install adoptopenjdk8. – Stevey Jul 23 '20 at 20:34
  • 1
    @user3562927 Installing [*Homebrew* (package manager)](https://en.wikipedia.org/wiki/Homebrew_(package_manager)) for the single goal of obtaining Java is like building a [landing strip](https://en.wikipedia.org/wiki/Runway) to park your car instead of just using your driveway. If you already have it, fine, use it. But suggesting *Homebrew* to those who simply need Java is poor advice. Apparently you are not the only easily-offended Homebrew fan, given the 5 down-votes left on this Answer without explanation. But I stand by my recommendation. – Basil Bourque Jul 24 '20 at 04:26
  • @BasilBourque brew is more useful than you think. It installs a lot of software so much easier, your answer is a proof for that :-/ – Daniel W. Dec 31 '20 at 20:44
  • 1
    @DanielW. The Question did not ask for a Brew solution, and did not even mention Brew. The Question asked about installing Java. There are several important issues to consider in installing Java; those issues I tried to cover. Apparently I have offended some Brew fans — that was not my intention. My intention was to pointedly address the Question at hand, as is the practice on Stack Overflow. And I stand by my position: Installing Brew *just to install Java* is overkill. Furthermore, using Brew to install Java will limit choices and ignore issues when it comes to various Java implementations. – Basil Bourque Dec 31 '20 at 20:56
  • Baroque indeed... – Mircea D. Feb 09 '21 at 14:04
21

If you have several Java versions on your machine and you want to choose it dynamically at runtime, i.e, in my case, I have two versions:

ls -la /Library/Java/JavaVirtualMachines
drwxr-xr-x  3 root  wheel    96B Nov 16  2014 jdk1.7.0_71.jdk/
drwxr-xr-x  3 root  wheel    96B Mar  1  2015 jdk1.8.0_31.jdk/

You can change them by modifying the /etc/profile content. Just add (or modify) the following two lines at the end of the file:

export JAVA_HOME=YOUR_JAVA_PATH/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

In my case, it should be like the following if I want to use:

Java 7:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

Java 8:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

After saving the file, please run source /etc/profile and it should work. Here are results when I use the first and second option accordingly:

Java 7:

java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)

Java 8:

java -version 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)

The process is similar if your java folder is located in different locations.

Hoa Nguyen
  • 10,964
  • 11
  • 42
  • 42
  • 1
    Why not making an alias for different version, like `alias java8=/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/bin/java`? – cglacet Apr 25 '19 at 12:14
20
brew cask install caskroom/versions/java8
Benjamin W.
  • 33,075
  • 16
  • 78
  • 86
Arun
  • 1,737
  • 10
  • 11
20

In the year 2021 you can use just brew

brew install openjdk@8

and you will find your JDK here:

/usr/local/opt/openjdk@8

I think sdkman is better than brew "raw" but you have to install it before have a jdk

curl -s "https://get.sdkman.io" | bash

then open a new shell and try list to see what you could install ;-)

sdk list java 
sdk install java 8.0.282.hs-adpt
freedev
  • 17,230
  • 4
  • 83
  • 98
  • `$ jenv add /usr/local/opt/openjdk@11` => `ln: /Users/nakilon/.jenv/versions/openjdk64-11.0.9: No such file or directory`. Ah, ok, needed to run those commands that are going to bash_profile. – Nakilon Feb 02 '21 at 16:51
  • Have you run brew before jenv? – freedev Feb 02 '21 at 16:56
19

Please, run the following commands and it will install Java 8 on OS X:

brew tap adoptopenjdk/openjdk
brew install --cask homebrew/cask-versions/adoptopenjdk8
shmck
  • 3,000
  • 3
  • 15
  • 28
Arefe
  • 6,963
  • 10
  • 60
  • 110
17

It seems that nobody has mentioned SDK man (https://sdkman.io/) yet.

SKD man allows installing multiple versions of Java on Mac and easy switching between these versions. More information is available at https://sdkman.io/usage.

For example:

$ sdk list java                                                                                                                                                                                                                       
================================================================================
Available Java Versions
================================================================================
   * 12.ea.20-open
     11.0.1-zulu
 > * 11.0.1-open
     10.0.2-zulu
     10.0.2-open
     9.0.7-zulu
     9.0.4-open
     8.0.192-zulu
     8.0.191-oracle
   + 8.0.181-oracle
     7.0.181-zulu
     1.0.0-rc-10-grl
     1.0.0-rc-9-grl
     1.0.0-rc-8-grl


================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

$ sdk install java 8.0.191-oracle

$ sdk use java 8.0.191-oracle

Using java version 8.0.191-oracle in this shell.                                                                                                                                                                                                      

$ java -version                                                                                                                                                                                                                        
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

$ sdk use java 11.0.1-open                                           

Using java version 11.0.1-open in this shell.

$ java -version                                                                                                                                                                                                                        openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
                                                                                                                                                                                                         ```


stderr
  • 868
  • 1
  • 9
  • 18
14

I have applications that use both Java 7 and 8 and have to go back and forth all the time.

I use this script written by Johan:

http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/

You can now set it at startup or call the script afterwards.
Install the JDK for Mac.

Java 7

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

Java 8

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


Updated recommendation!!:

Use jenv https://www.jenv.be/ and homebrew.

Then its just jenv global oracle6401.6.0.39 and its set.

Nathan Dunn
  • 417
  • 5
  • 14
  • 1
    +1: i use this script and i agree, it's pretty useful for devs who have multiple projects that require different versions of Java. – barclay Aug 28 '15 at 15:18
  • 9
    There is really no need to set any scripts as long as you only need to use a specific version system-wide. Basically all you need to do is add to your `~/.bashrc` or `~/.bash_profile`: *export JAVA_HOME="/usr/libexec/java_home -v 1.8"* and also add your `$JAVA_HOME/bin` to `$PATH` if the java installer didn't do it already. (NOTE: replace double quotes with backticks for /usr/libexec/java_home, can't enter literal backticks in comments..) – ccpizza Sep 02 '15 at 09:40
  • if you want to install java 7 (along side java 8) via homebrew, the command is `brew tap caskroom/versions` followed by `brew cask install java7`. – icfantv Jan 19 '16 at 20:18
  • 3
    [jenv](https://github.com/gcuisinier/jenv) is a very convenient tool for managing multiple versions of Java, either globally or locally per-directory. – Christian Long Mar 23 '16 at 14:44
11

Run these commands on mac High Sierra

brew update
brew tap caskroom/versions
brew cask install java8

and check with command

java -version
TLbiz
  • 399
  • 5
  • 7
  • Getting this: ```Error: Download failed on Cask 'java8' with message: Download failed: https://download.oracle.com/otn-pub/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-macosx-x64.dmg``` – Siddhartha Apr 18 '19 at 04:15
7

Using brew

brew install Caskroom/cask/java
Santhosh
  • 24,879
  • 8
  • 71
  • 84
7

Best way is to use Brew package manager but the command

 brew cask install java8

fails with error:

Error: No available formula with the name "java8" 

So use

brew cask install caskroom/versions/java8

How did I find "caskroom/versions/java8": using brew search command:

brew cask search java8
Nav
  • 1,024
  • 12
  • 14
7

If you are using it NOT for personal use, you might want to use OpenJDK instead to avoid any potential lawsuit from Oracle.

brew cask install adoptopenjdk8
Edmund Lee
  • 2,306
  • 17
  • 26
  • find /usr/local/Homebrew/Library/Taps/ | grep -i jdk | xargs rm -v if you happen the get the "Error: Cask adoptopenjdk8 exists in multiple taps:" error ... – Yordan Georgiev Aug 02 '19 at 08:05
7

If you are on a Mac, then Homebrew is the way to install stuff.

It seems that version 8 is no longer the most recent, so it isnt available using the default brew cask install java.

Instead I managed by doing the following:

brew install homebrew/cask-versions/

If this fails, just try the next one directly:

brew install homebrew/cask-versions/adoptopenjdk8

Test with brew cask list or java -version

Dennis Jaheruddin
  • 19,745
  • 7
  • 58
  • 100
Anas
  • 827
  • 9
  • 11
  • +1, that works for me on macOS 10.12.6 Sierra. (Or brew cask install adoptopenjdk/openjdk/adoptopenjdk8) – McAllister Bowman Dec 14 '19 at 08:01
  • +1 The first one failed (Error: No available formula with the name "homebrew/cask-versions/" ), but the second one seemed to work. Updated answer to avoid scaring people off with the first faillure. – Dennis Jaheruddin May 30 '20 at 09:36
6

for 2021 this one worked for me

brew tap homebrew/cask-versions


brew install --cask adoptopenjdk8
JavaQuest
  • 479
  • 5
  • 18
5

brew cask commands were disabled on 2020-12-21 with the release of Homebrew 2.7.0.

Use the below commands to install JDK

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

Niraj Sonawane
  • 6,954
  • 7
  • 49
  • 76
4

Simplest is to download the dmg file from following site and install by double click

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

look for available JVMs from home directory

ls -al /Library/Java/JavaVirtualMachines

and update the .bash_profile with relevent version

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_XXX.jdk./Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

and finally

source ~/.bash_profile
Sash Sinha
  • 11,515
  • 3
  • 18
  • 35
vimal krishna
  • 2,452
  • 25
  • 21
4

Install with Homebrew

The version of Java available in Homebrew Cask previous to October 3, 2018 was indeed the Oracle JVM. Now however, it has now been updated to OpenJDK. Be sure to update Homebrew and then you will see the lastest version available for install.

1. install Homebrew if you haven't already. Make sure it is updated:

brew update

2. Add the casks tap, if you haven't already (or you are not seeing older Java versions anymore with step #3):

brew tap homebrew/cask-versions

3. and for the AdoptOpenJDK versions, add that tap:

brew tap adoptopenjdk/openjdk

These casks change their Java versions often, and there might be other taps out there with additional Java versions.

4. Look for installable versions:

brew search java 

or for AdoptOpenJDK versions:

brew search jdk     

5. Check the details on the version that will be installed:

brew cask info java

or for the AdoptOpenJDK version:

brew cask info adoptopenjdk

6. Install a specific version of the JDK such as java11, adoptopenjdk8, or just java or adoptopenjdk for the current. For example:

**brew cask install java**

**brew cask install java8**

**brew cask install java11**

You can use the fully qualified path to older versions as well:

brew cask install homebrew/cask-versions/java11
Wazery
  • 13,971
  • 15
  • 55
  • 91
Dean Jain
  • 1,477
  • 15
  • 12
  • Presumably I did something wrong, but when trying to do java8 I got an error: Error: Cask 'java8' is unavailable: No Cask with this name exists. – Dennis Jaheruddin May 30 '20 at 09:31
2

Easiest way

1) brew cask install java

2) java -version

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)

P.S - Cask is an extension to Homebrew that is intended to manage large Mac binaries and graphical applications, but using the Homebrew interface. Also see this answer on Apple StackExchange.

charlesreid1
  • 3,218
  • 2
  • 26
  • 43
sapy
  • 6,665
  • 6
  • 40
  • 51
2

Try :

brew cask install java 8

it will give the below result

8tracksradiohelper       adoptopenjdk8            amitv87-pip              
corretto8                icons8                   vmware-fusion8           
x48                      zulu8

Next enter:

brew cask install adoptopenjdk8

---- java 8 will be installed in Mac.

Greenonline
  • 1,231
  • 6
  • 19
  • 25
args
  • 294
  • 2
  • 13
  • `brew cask install java 8` gave me a completely different list: `eclipse-java`, `netbeans-java-ee`, `oracle-jdk-javadoc`, `eclipse-javascript`, `netbeans-java-se` – Greenonline Dec 05 '20 at 12:02
  • This no longer works. I have `Homebrew 2.7.1` running on Mac OS Catalina 10.15.4 Using `brew tap` followed by `brew install --cask` from another comment apparently worked fine. – timurb Dec 29 '20 at 14:56
2

You can try this:

$ brew search jdk
$ brew cask install homebrew/cask-versions/adoptopenjdk8
$ /usr/libexec/java_home

 

Dino
  • 6,207
  • 8
  • 28
  • 62
geek
  • 333
  • 3
  • 14
-1

As of May 3, 2020, this site has a download link for jre8u251: https://java.com/en/download/mac_download.jsp

Kem Mason
  • 1,118
  • 12
  • 25
-4

Below steps worked for me.

1) Uninstall all jdks

In the Terminal window Copy and Paste the command below:

sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefpane

2) Install APPLE jdk.

https://support.apple.com/kb/DL1572?locale=en_US

3) Download latest JDK from Oracle and install it , for me it was JDK 1.82

http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

Thats all it will work like a charm.

flavio.donze
  • 6,077
  • 9
  • 41
  • 69
sembian
  • 11