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 condabase 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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 hadopenjdk
installed in myconda
base
env (it was required by another program installed with conda) and I could not get this solution to work until I uninstalledopenjdk
from my activeconda
env or switched to an env withoutopenjdk
installed. I'm sure it was a problem with myPATH
, 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 ownopenjdk
and uninstalledopenjdk
from my activeconda
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 setJAVA_HOME
. E.g. as soon as I start a new shell window and typeecho $JAVA_HOME
, nothing appears and upon inspection of variables listed byenv
,JAVA_HOME
does not appear. Interestingly, if I typejava -version
, it does show myadoptopenjdk14
as the current version even though the variableJAVA_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.