0

I did my due diligence and researched. I followed the following steps:

  1. /usr/libexec/java_home -V

result was:

Matching Java Virtual Machines (2):
    11.0.13 (x86_64) "Oracle Corporation" - "Java SE 11.0.13" /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home
    1.8.0_372 (x86_64) "Homebrew" - "OpenJDK 8" /usr/local/Cellar/openjdk@8/1.8.0+372/libexec/openjdk.jdk/Contents/Home
  1. export JAVA_HOME=/usr/libexec/java_home -v 1.8.0_372

  2. echo $JAVA_HOME

result was:

/usr/local/Cellar/openjdk@8/1.8.0+372/libexec/openjdk.jdk/Contents/Home
  1. But when I do java -version, the following result shows up:

    java version "11.0.13" 2021-10-19 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.13+10-LTS-370) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.13+10-LTS-370, mixed mode)

Result shows default java is still Java 11. I want to switch it to use Java 1.8

Can anyone help me on this?

  • Does this answer your question? [How to set java --version corresponding to JAVA\_HOME on Mac OS 12.6](https://stackoverflow.com/questions/76512739/how-to-set-java-version-corresponding-to-java-home-on-mac-os-12-6) – Jean-Baptiste Yunès Jul 06 '23 at 06:41

2 Answers2

2

I use https://sdkman.io/ to manage different java versions on my mac(M1).

I've installed several java versions using sdkman and it is easy to switch in between those versions using sdkman with one command.

Dinithi
  • 518
  • 5
  • 17
0

I use jenv to switch between different java versions on mac.

>brew info jenv
==> jenv: stable 0.5.6 (bottled), HEAD
Manage your Java environment
https://www.jenv.be/
/opt/homebrew/Cellar/jenv/0.5.6 (86 files, 78KB) *
  Poured from bottle on 2023-02-15 at 07:31:25
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/jenv.rb
License: MIT
==> Options
--HEAD
    Install HEAD version
==> Caveats
To activate jenv, add the following to your shell profile e.g. ~/.profile
or ~/.zshrc:
  export PATH="$HOME/.jenv/bin:$PATH"
  eval "$(jenv init -)"

With

jenv local 11.0

or

jenv local 17.0

for example, I can switch do different versions of installed java.

Michael Konietzka
  • 5,419
  • 2
  • 28
  • 29