Upgrade to OpenJDK Temurin using Homebrew

By Rex Resurreccion Nov 11, 2021
Download and install Java

How to upgrade OpenJDK in MacOS using brew?

In my previous post about Setting up Maven Cucumber, I used AdoptOpenJDK to install Java 11. This time, I will upgrade my environment to Java 17. But I still want to manage my Java versions using Homebrew.

Upgrade to OpenJDK Temurin 17 LTS by Eclipse. This time I will get it from a new source since the AdoptOpenJDK repository is now deprecated. The command to install is very simple.

brew install --cask temurin

To use a different version of Java, you need to activate a third-party repository (TAP).

brew tap homebrew/cask-versions
brew install --cask temurin8

Using multiple Java versions

After I upgrade to OpenJDK Temurin 17 LTS, I still want to keep the previous versions of my Java. And to easily switch in between versions, I can create an alias in my .bash_profile.

export JAVA_17_HOME=$(/usr/libexec/java_home -v 17)
export JAVA_11_HOME=$(/usr/libexec/java_home -v 11.0.11)
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8.0_242)

alias java17="export JAVA_HOME=$JAVA_17_HOME"
alias java11="export JAVA_HOME=$JAVA_11_HOME"
alias java8="export JAVA_HOME=$JAVA_8_HOME"

#set default to Java 17

To switch to Java 11 in your terminal.


And that’s it for this quick tutorial. Happy coding!

© YippeeCode.com 2020