DEV Community

Steve
Steve

Posted on • Originally published at dev.cavender.io on

MacOS OpenJDK Maintenance

What is OpenJDK?

An open-source implementation of the Java platform SE. To read more check out official site.

Why have multiple versions?

Why not? Not all apps are able to keep up with Java versions and those that do might need some time when a new version comes out. For example: I’m working with React-Native building mobile apps for both iOS and Android. To build the Android app it uses Gradle 6.5 which doesn’t support the latest version of Java (16) yet.

Installing

I have OpenJDK installed through AdoptOpenJDK using brew. I like to keep all my apps and libs as up-to-date as possible so I run brew upgrade a lot. One of those times it upgraded AdoptOpenJDK to 16. Lucky for me they also publish older versions on brew but there’s an extra step.

My initial thought was to run brew install adoptopenjdk@15 but it didn’t work. The versioned casks are contained in their Tap which I found out by checking out their brew page and subsequently their open-source tap code.

So the fix was to get into the tap (brew tap adoptopenjdk/openjdk) and run the command above again.

Switching between versions

Now I have two versions of OpenJDK available to my system: 16 and 15. To switch between them I found a little function to pop into my .zshrc file:

jdk() {
  export JAVA_VERSION=$1
  java -version
}

Enter fullscreen mode Exit fullscreen mode

Now to switch between JDK versions I run jdk 15 or any version I have installed.

Warp.dev image

The best coding agent. Backed by benchmarks.

Warp outperforms every other coding agent on the market, and gives you full control over which model you use. Get started now for free, or upgrade and unlock 2.5x AI credits on Warp's paid plans.

Download Warp

Top comments (0)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server ⏰

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!