34

At the moment Java 8 is still required for some apps like:

  • Android SDK / Android Studio
  • Jenkins
  • Ionic ...

With brew install java the latest Version is installed. But how to install Java 8?

2
  • 1
    Wouldn't this be better suited at StackExchange? Commented Dec 14, 2018 at 0:46
  • If you use sdkman! then it can run on Mac OSX, Linux, Cygwin, Solaris and FreeBSD. sdk ls java and sdk use 8.0.192-zulu (for example) Commented Dec 14, 2018 at 1:24

5 Answers 5

79

The older Oracle JDKs are gone from Homebrew now. Use OpenJDK instead:

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8

OpenJDK is a drop-in replacement for the Oracle JDK in most places, so this should work fine for you with no code or build process changes.

Sign up to request clarification or add additional context in comments.

5 Comments

It's worth noting that brew tap caskroom/versions includes adoptopenjdk8 too. I personally prefer that since it includes other useful things. Use the answer as-is for the targeted approach.
Thanks for the tip! I think I'm going to stick with the adoptopenjdk/openjdk tap for my answer, since it's the one that's maintained by AdoptOpenJDK themselves, so is likely to be the canonical source for OpenJDK formulae, and it includes all the other JDK versions 8-12 and variants as well. But yeah, if you want versions for other Cask things too and have it tapped already, the adoptopenjdk8 from caskroom/versions should work just fine.
Oct-2019 this works: brew cask install adoptopenjdk/openjdk/adoptopenjdk8
brew cask install adoptopenjdk8 fails on my machine with Cask adoptopenjdk8 exists in multiple taps:. @ruhong 's answer fixes it.
Looks like the homebrew/cask-versions tap has added a formula for adoptopenjdk8 (see github.com/Homebrew/homebrew-cask-versions/commit/…). In that case, you can probably skip the brew tap adoptopenjdk/openjdk step, and you won't have to qualify the name and brew cask install adoptopenjdk8 would still work.
13

This answer is outdated.

You can install Java 8 on macOS Mojave like this:

brew tap caskroom/versions
brew cask install java8

In case the latest java version was already installed, uninstall it with:

brew cask remove java

4 Comments

FWIW, it appears that the versions tap has been deprecated, and version support moved to core (from the warning that I subsequently got)
I got "Error: Cask 'java' is not installed." and then check java - version and still showing java version "11.0.2" 2019-01-15 LTS
Note: this no longer works as of April 2019 because the java8 cask is gone. Need to use OpenJDK casks instead for older versions of Java.
>> this is outdated
4

Updated commands that are working now:

brew tap homebrew/cask
brew tap homebrew/cask-versions
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8

1 Comment

This is awesome. It sidesteps the error that brew install java gives: "openjdk: macOS Catalina or newer is required for this software. Error: openjdk: An unsatisfied requirement failed this build."
3

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

Comments

0
brew reinstall --cask adoptopenjdk

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.