DEV Community

Discussion on: How to manage multiple Java JDK versions on macOS X

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.