Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Java 8 on osx macOS Mojave with Homebrew?

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?

like image 542
d0x Avatar asked Dec 14 '18 00:12

d0x


People also ask

Where does Homebrew install Java on Mac?

The MacOS Java install location is /Library/Java/JavaVirtualMachines/ . Certain formulae, such as openjdk , do not automatically install into the actual /Library/Java/JavaVirtualMachines/ . Instead, the formula will suggest to you in the installation/info caveats to symlink it into that location.


4 Answers

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.

like image 170
Andrew Janke Avatar answered Oct 11 '22 04:10

Andrew Janke


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
like image 43
d0x Avatar answered Oct 11 '22 04:10

d0x


Updated commands that are working now:

brew tap homebrew/cask
brew tap homebrew/cask-versions
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
like image 4
Shraddha Avatar answered Oct 11 '22 04:10

Shraddha


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
like image 3
Lyncean Patel Avatar answered Oct 11 '22 05:10

Lyncean Patel