Installing Java in 2021

Woah! Its 2021 and I’ve just joined a new team and they mostly use Java to build awesome web applications. Super! Exciting! I remember Java! Let me at it!

New beginnings. Old problems.

It is the first day on my new project. I’m given a long list of items to install for developing locally. Near the top of that list is a requirement for Java 14. ‘Cool!’ I think to myself. I’ve never used a version > 11 in production before!

A little further down the list I see Java 11. ‘Hmmm… two different Java versions okay.’ Well, I know JDK 11 is a long term support release maybe the team is using something experimental from 14?

Wanting to get going quickly I start working through the list. I have a vague memory that in the past actually getting a working Java installation was a little fiddly. I also remember having multiple JVMs side by side can be a little tricky too.

‘I’m probably being too pessimistic’ continues my internal monologue. Surely in 2021 things have been made as easy as running, brew install java(version) right???

Well… yes and no. - Helpful answer right?

brew install java

Homebrew, the community ran package manager which makes OSX much more developer friendly does actually have an OpenJDK Formulae ready and waiting to be installed. In fact it has two:

~> brew update
~> brew search java
==> Formulae
java                             java11                           javarepl  

more omitted results...

The Formula java is the latest stable release of OpenJDK, at time of writing that is version 15. Unsurprisingly, java11 is the latest release of OpenJDK11.

Sooooo… hopefully…

~> brew install java
==> Downloading https://homebrew...
==> Pouring openjdk-15...
... 
==> Summary
🍺  /usr/local/Cellar/openjdk/15.0.1: 614 files, 323.8MB
~> java --version
==> openjdk 15.0.1 2020-10-20

Success! I now have a working java 15 installation!

So I can install OpenJDK 15 and 11 very easily! Fantastic! However I don’t see a way to install Java 14 yet… Oh well, not to worry. Maybe there are is a brew cask available somewhere to install a specific Java Development Kit?

AdoptOpenJDK

A quick google later and I stumble upon a GitHub repo from AdpotOpenJDK. The repo, adoptopenjdk/homebrew-openjdk, is a curated list of open JDK Formulae ready to be installed via brew. The Readme is very clear and concise explaining how to install the specific version of Java you want.

Following the instructions from that readme:

~> brew tap AdoptOpenJDK/openjdk
==> Tapping adoptopenjdk/openjdk

~> brew install --cask adoptopenjdk14
==> Installing Cask adoptopenjdk14

Et voila, installing Java, even multiple versions, is pretty simple in 2021. A simple brew install java will pull down the latest stable OpenJDK release and the AdpotOpenJDK project makes it easy to install a specific version!

A simple way to swap between a specific JDK version is also documented in the AdoptOpenJDK Readme. However I’ve found JEnv which I prefer and might write a 101 on later.

Thanks for reading! :-)

Disclaimer: Running a non LTS JVM in production is interesting but probably okay if you keep up-to-date with new releases. openJDK15 is the current general release so I’ll be trying to figure out why 14 is being used in this project.