1290

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?

6
  • 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
    Commented Jun 21, 2014 at 17:49
  • Similar: How to use jdk without jre in Java 11 Commented Jun 19, 2020 at 1:27
  • brew install openjdk@8 Commented Nov 1, 2021 at 2:28
  • 3
    brew install --cask temurin8 # Temurin is the official successor to adoptopenjdk
    – Simon B.
    Commented Feb 24, 2022 at 22:17
  • Update on 2022/8: install it with " brew install --build-from-source openjdk@8"
    – aminbadri7
    Commented Aug 15, 2022 at 22:43

34 Answers 34

2267

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.

40
  • 104
    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
    Commented Dec 16, 2015 at 17:22
  • 80
    Thanks, it's amazing how horrible the Java installation process using the "official" links/docs are.
    – enderland
    Commented Feb 15, 2016 at 22:31
  • 16
    @tandrewnichols I just ran brew cask install java on my El Capitan Mac and it's downloading jdk-8u112-macosx-x64.dmg.
    – Calrion
    Commented Oct 24, 2016 at 0:43
  • 58
    Error: Cask 'java8' is unavailable: No Cask with this name exists.
    – Elderry
    Commented Aug 16, 2018 at 9:01
  • 104
    The workaround for now is to brew tap homebrew/cask-versions and use brew cask install homebrew/cask-versions/adoptopenjdk8 Commented Apr 19, 2019 at 21:31
875

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 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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
29
  • 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
    Commented Oct 14, 2015 at 14:19
  • 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. Commented Apr 14, 2016 at 12:51
  • 23
    Error: Cask 'java8' is unavailable: No Cask with this name exists.
    – user924
    Commented Jun 9, 2019 at 15:35
  • 8
    $ 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 Commented Aug 26, 2019 at 12:01
  • 5
    brew tap homebrew/cask-versions and brew cask install adoptopenjdk8 works for me on Hi Sierra 10.13.6
    – xjlin0
    Commented Oct 5, 2019 at 14:30
168

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
10
  • 3
    Is there any difference in using AdoptOpenJDK/openjdk instead of using homebrew/cask-versions/adoptopenjdk8 Commented Apr 27, 2019 at 5:52
  • 1
    @SeanBreckenridge - the HomeBrew team are working on it, at the moment it looks like AdoptOpenJDK will be used, but there is still some uncertainty, see the currently open issue github.com/AdoptOpenJDK/homebrew-openjdk/issues/106 for details!
    – Dave Kerr
    Commented May 11, 2019 at 3:35
  • 1
    brew cask install homebrew/cask-versions/adoptopenjdk8 worked for me Commented Nov 13, 2019 at 23:08
  • 2
    this worked for me brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
    – Shams
    Commented May 23, 2021 at 15:30
  • 2
    brew install --cask adoptopenjdk/openjdk/adoptopenjdk8 worked for MacOS Monterey, 12.1. cask is no longer a brew command, see here, stackoverflow.com/questions/66286088/…
    – vpap
    Commented Jan 5, 2022 at 19:25
165

In 2023, you can use just brew

brew install openjdk@8

Apple silicon users should execute this first

env /usr/bin/arch -x86_64 /bin/zsh --login

and maybe you need to update PATH env:

export PATH="/usr/local/opt/openjdk@8/bin:$PATH"

…for the future give a try to sdkman, is better than brew

curl -s "https://get.sdkman.io" | 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

16
  • 1
    the brew method worked also had to update the path variables
    – Shivam
    Commented Jul 6, 2021 at 10:58
  • 1
    you need to run export PATH="/usr/local/opt/openjdk@8/bin:$PATH" after installing brew list for install packages brew info $package_name for information of package Commented Jul 15, 2021 at 6:18
  • 1
    as simple as that! Commented Apr 27, 2022 at 12:05
  • 2
    Had to do brew install --build-from-source openjdk@8 to make it work Commented May 3, 2022 at 12:46
  • 3
    sdkman is a blessing Commented Jul 11, 2022 at 7:44
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.

11
  • 10
    It helped me with installing specific version of java. Now when java 9 is out, running "brew cask install java" installs java 9. "brew cask install java8" wasn't working for me until I ran "brew tap caskroom/versions".
    – interrupt
    Commented Oct 15, 2017 at 18:34
  • 6
    Yes, brew tap caskroom/versions is required before installing java8
    – hendrix
    Commented Nov 10, 2017 at 9:25
  • 12
    or just brew install homebrew/cask-versions/java8 for the win! Commented Jun 6, 2018 at 22:48
  • 5
    It is not possible to install Java8 using Brew anymore because of Oracle license changes. Java8 is not available for public download anymore. Commented Apr 24, 2019 at 13:07
  • 3
    See stackoverflow.com/a/55775566/9306378 if you still want to use java8. Note that this uses OpenJDK though.
    – Polpetta
    Commented Apr 29, 2019 at 9:46
88

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
5
  • 4
    Best solution! Thank you! Commented Feb 4, 2020 at 14:48
  • 1
    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
    Commented Apr 22, 2020 at 7:47
  • 1
    Works like a charm, brew cask install adoptopenjdk/openjdk/adoptopenjdk8
    – jeadonara
    Commented May 16, 2020 at 14:35
  • 1
    This is the best answer indeed! Ideal for folks (like me) who have and need to manage multiple versions of java Commented Sep 4, 2020 at 11:09
  • 2022: Mac 12.x : brew cask` is no longer a brew command. Use brew <command> --cask instead. brew install adoptopenjdk/openjdk/adoptopenjdk8 --cask
    – RRy
    Commented May 4, 2022 at 19:44
70

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:

3
  • 3
    Good example using Docker, not sure why you got a downvote before.
    – Andrew
    Commented Apr 28, 2016 at 14:25
  • 35
    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
    Commented Dec 14, 2016 at 22:18
  • 1
    especially for native java development (e.g. using SWIG, JNI and LIBRARY_PATH)
    – Mizux
    Commented Apr 15, 2019 at 9:23
29

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.

4
  • 9
    This answer is odious. Just use brew cask install adoptopenjdk8.
    – Stevey
    Commented Jul 23, 2020 at 20:34
  • 2
    @user3562927 Installing Homebrew (package manager) for the single goal of obtaining Java is like building a landing strip 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. Commented Jul 24, 2020 at 4: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.
    Commented Dec 31, 2020 at 20:44
  • 2
    @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. Commented Dec 31, 2020 at 20:56
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

1
  • jenv is quite easy and super useful. I have multiple projects that need java 8 and 11 Commented Mar 7, 2019 at 13:15
24

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

Note:

adoptopenjdk8 has been officially discontinued upstream. It may stop working correctly (or at all) in recent versions of macOS. So, this is working at the moment, but, please, don't use this answer to install Java 8

2
  • Glad that helped you :)
    – Arefe
    Commented Dec 15, 2020 at 12:01
  • should be the only accepted solution, works like charm. Commented May 3, 2021 at 12:56
23

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.

1
  • 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
    Commented Apr 25, 2019 at 12:14
22

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)
                                                                                                                                                                                                         ```


2
  • I'm getting this pop-up : ---------------------------- Stop! java 8.0.191-oracle is not available. Possible causes: * 8.0.191-oracle is an invalid version * java binaries are incompatible with your platform * java has not been released yet ----------------------------
    – aksyuma
    Commented Apr 20, 2022 at 18:35
  • Indeed 8.0.191-oracle is not among the list anymore. You can use sdk list java to check other distributions
    – stderr
    Commented Apr 21, 2022 at 8:44
19
brew cask install caskroom/versions/java8
17

for 2021 (also 2022 and 2023) this one worked for me

brew tap homebrew/cask-versions


brew install --cask adoptopenjdk8
2
  • This worked in 2022 , after installation the following commands can be used to validate your installation java , java -version . The commands java --version and which java do not give proper results though.
    – mdabdullah
    Commented Apr 21, 2022 at 20:02
  • 1
    Small update to this. brew suggests to use brew install --cask temurin8 instead. (I did not realize Temurin made also Java 8 version) Commented Feb 28 at 10:26
16

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.

4
  • 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
    Commented Aug 28, 2015 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
    Commented Sep 2, 2015 at 9: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
    Commented Jan 19, 2016 at 20:18
  • 3
    jenv is a very convenient tool for managing multiple versions of Java, either globally or locally per-directory. Commented Mar 23, 2016 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
1
  • 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
    Commented Apr 18, 2019 at 4:15
11

As of Year - 2021

brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
1
  • 3
    This is the one that worked for me today. Commented Dec 4, 2021 at 22:30
8

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

2
  • +1, that works for me on macOS 10.12.6 Sierra. (Or brew cask install adoptopenjdk/openjdk/adoptopenjdk8) Commented Dec 14, 2019 at 8: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. Commented May 30, 2020 at 9:36
8

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

7

Using brew

brew install Caskroom/cask/java
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
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
1
  • 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 ... Commented Aug 2, 2019 at 8:05
7

You can try this:

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

 

5

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
5

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
1
  • 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. Commented May 30, 2020 at 9:31
5

brew search openjdk find some openjdk formulae, in 2021, brew offer openjdk11 and openjdk8 as options.

1
  • what should be next command after searching? Commented Oct 11, 2021 at 8:36
5

MacOS Big Sur 2021 Java 8 installation guide:

  1. Go to https://profile.oracle.com/myprofile/account/create-account.jspx and sign up if not already;
  2. Go to https://www.oracle.com/java/technologies/downloads/#jdk17-mac
  3. Select "Java 8";
  4. Select "macOS";
  5. Press on "jdk-8u301-macosx-x64.dmg"; Java 8 download page
  6. Check the checkbox;
  7. Press "Download jdk-8u301-macosx-x64.dmg";
  8. Open the downloaded file;
  9. Follow installation guide;

Enjoy =)

2
  • In order to test if the installation was successful run the following command on terminal 'javac -version'
    – Steven
    Commented Mar 7, 2022 at 17:48
  • Thanks @Vladimir Kuzomenskyi, I have installed successfully with help of your simple steps. Commented Sep 23, 2022 at 13:01
5

Eclipse Temurin is the official successor to adoptopenjdk. So, as of May 2022, I would use the following

brew install --cask temurin8

When the installation is done, JDK 8 is installed in /Library/Java/JavaVirtualMachines/temurin-8.jdk

4

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.

1
  • 1
    it always installs the latest version
    – Ray Garner
    Commented Jan 10, 2020 at 7:54
4

As of 2023, brew install --cask zulu8 didn't work for me on Apple chip. brew install openjdk@8 also didn't not. The only one solution worked for me was brew install --cask adoptopenjdk8 and then of course vim ~/.zshrc with export JAVAC_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/ inside that file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.