To uninstall AdoptOpenJDK installed via Homebrew,
Copybrew uninstall adoptopenjdk8
To uninstall OpenJDK installed via Homebrew,
Copybrew uninstall openjdk8
Answer from user5780831 on Stack OverflowTo uninstall AdoptOpenJDK installed via Homebrew,
Copybrew uninstall adoptopenjdk8
To uninstall OpenJDK installed via Homebrew,
Copybrew uninstall openjdk8
Answer from user5780831 on Stack OverflowTo uninstall AdoptOpenJDK installed via Homebrew,
Copybrew uninstall adoptopenjdk8
To uninstall OpenJDK installed via Homebrew,
Copybrew uninstall openjdk8
The /usr/bin/java and other related tools are macOS shims that run a specific version of Java, as defined by the JAVA_HOME variable.
This variable is usually set in your ~/.bashrc file:
Copyexport JAVA_HOME=$(/usr/libexec/java_home -v1.8)`
You can check the current value:
Copy$ echo $JAVA_HOME
/usr/local/Cellar/openjdk@8/1.8.0-392/libexec/openjdk.jdk/Contents/Home
You may have multiple versions of Java installed, to list them all:
Copy$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
21.0.1 (x86_64) "Homebrew" - "OpenJDK 21.0.1" /usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
1.8.0_392 (x86_64) "Homebrew" - "OpenJDK 8" /usr/local/Cellar/openjdk@8/1.8.0-392/libexec/openjdk.jdk/Contents/Home
/usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
In my case, you can see there are three versions of OpenJDK installed via homebrew. I can look them up in the list of installed packages:
Copy$ brew list | grep -iE 'java|jdk|temurin'
openjdk
openjdk@17
openjdk@8
If I wanted to remove all of them, I could do brew uninstall them one by one, or:
Copy$ for pkg in $(brew list | grep -iE 'java|jdk|temurin'); do brew uninstall $pkg; done
Videos
You can install the java using below-mentioned command:
brew uninstall --ignore-dependencies java
To ensure that you are using java 8, you need to add path into bash file(~/.bashrc or ~/.zshrc)
Command to set path:
export PATH=/usr/lib/jvm/java-1.8.0-amazon-corretto/bin:$PATH
After that do:
source (~/.bashrc or ~/.zshrc)
check the java version again. Hope, it helps you.
I think @Maninder gave you the answer you were looking for.
Later, If you want to use multiple versions of Java, How about using 'jEenv'? (You may have already tried this method.)
"jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable".
This is a greate answer to installing/using jEnv.
Mac OS X and multiple Java versions