How to install Java 9 and 10 on Mac with Homebrew?

I tried to install Java 9 and 10 on macOS with Homebrew:

brew cask install java9

I got the following error:

Error: Cask ‘java9’ is unavailable: No Cask with this name exists.

and:

brew cask install caskroom/versions/java9

gave me:

Error: Cask ‘java9’ is unavailable:

‘/usr/local/Homebrew/Library/Taps/caskroom/homebrew-versions/Casks/java9.rb’ does not exist.

Why doesn’t this work and how can I install Java on macOS?

Answer

Oracle does not support Java 9 and Java 10 releases. users are advised to use Java 11 instead. Brew removed casks for both releases as well.

Here are the official links from oracle which mention that they removed support for Java 9 and Java 10.

https://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html https://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html

When you will do brew cask install java it will install the latest version while you can still install java 8 by using brew cask install java8

Below github link from homebrew clearly mentioned that when oracle stops supporting java10 then they will remove java10 cask.

https://github.com/Homebrew/homebrew-cask-versions/pull/6305

Summary

Java 9 and Java 10 were non LTS(Long time support) releases from oracle and according to new release pattern from oracle, they will stop supporting non LTS release as soon as new version released thus Java 9 lost its support when 10 was released and Java 10 lost its support when 11 was released but Java 8 and Java 11 are LTS release so oracle will support it for long time.

Oracle stops supporting means download for those versions are not publicly available.