Home > Back-end >  confusion by java versions in my MacOs(Catalina)
confusion by java versions in my MacOs(Catalina)

Time:10-25

Recently, I want to upgrade my java from 8 to 11. Then checking my machine using java -version, it shows as follows:

java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

Then, I think there is only java-8 there. But then I use homebrew with brew install java11 it shows this:

==> Formulae
app-engine-java             java                        javacc     jslint4java                 pdftk-java
google-java-format          java11 ✔                    javarepl   libreadline-java
==> Casks
eclipse-java                        eclipse-javascript                  oracle-jdk-javadoc                  homebrew/cask-versions/java-beta

If you meant "java" specifically:
It was migrated from homebrew/cask to homebrew/core.

I am confused now: are these 2 versions installed in my machine, or only one there? If 2 here, how to I specify the path if I want to use java11.

CodePudding user response:

Even though you installed java 11, your JAVA_HOME might be pointing to java 8. You can override this variable by initializing it your shell initialization scripts. You can add the following in your .zshrc or .bash_profile and it should work as expected.

export JAVA_HOME=`/usr/libexec/java_home -v 11`

CodePudding user response:

In Homebrew, java11 is an alias for the formula openjdk@11. What you want is a cask, specifically temurin11, which can be installed by running this command:

brew install homebrew/cask-versions/temurin11

(Temurin is the official successor of AdoptOpenJDK.)

  • Related