DEV Community

How to manage multiple Java JDK versions on macOS X

Marc Stammerjohann on April 16, 2020

Here is a quick tip on how to install multiple Java JDK versions (8, …, 11, …, 14 etc.) on macOS X and how to switch between them for your applicat...
Collapse
 
leowill01 profile image
Leo Williams • Edited

Thank you for this recent tutorial on how to manage Java versions with Homebrew. Most other guides I tried to follow are written for outdated brew functionality.

Quick warning: This does NOT seem to work if you have Java installed in some way through conda. I had openjdk installed in my conda base env (it was required by another program installed with conda) and I could not get this solution to work until I uninstalled openjdk from my active conda env or switched to an env without openjdk installed. I'm sure it was a problem with my PATH, but since I couldn't figure it out after a while, I just made a new conda env with the tools that automatically install their own openjdk and uninstalled openjdk from my active conda base env. Everything seems to work great now, thanks a ton!

Edit: I seem to be running into a problem where the command export JAVA_HOME=[...] in my ~/.zshrc doesn't seem to actually set JAVA_HOME. E.g. as soon as I start a new shell window and type echo $JAVA_HOME, nothing appears and upon inspection of variables listed by env, JAVA_HOME does not appear. Interestingly, if I type java -version, it does show my adoptopenjdk14 as the current version even though the variable JAVA_HOME doesn't exist. Any idea why? It does set itself when I run one of the aliases, but that requires manually running the alias.

Edit 2: I found the problem: It was because I still had some code in my .zshrc from trying a previous solution.

Collapse
 
awwsmm profile image
Andrew (he/him)

Hey Marc, you should check out SDKMAN!, you can easily switch between (but also install and uninstall) different Java (and Scala, and Gradle, and Kotlin, Groovy, sbt, Spring Boot, ...) versions using SDKMAN! It's seriously amazing, and really easy to use.

Collapse
 
marcjulian profile image
Marc Stammerjohann

Hi Andrew, thanks for the tip! I'll it try out!