1

I am using macOS Monterey (v 12.0.1). Below is my Java version :

$ java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

First of all I do not understand "1.8.0_281", does it mean it is java 8?

I want to update the Java version to 11. So, I have downloaded and installed jdk-11.0.13_osx-x64_bin.dmg, it shows successfully installed. But now when I check java -version still it shows java version "1.8.0_281". How can I update my java version to java 11 ?

Madasu K
  • 1,813
  • 2
  • 38
  • 72
  • 2
    1) Yes. 2) You need change what `java` is resolving to; see https://stackoverflow.com/a/24657630/139985 – Stephen C Dec 11 '21 at 09:16
  • Did you read it? You can find the answer below the link. https://stackoverflow.com/questions/52524112/how-do-i-install-java-on-mac-osx-allowing-version-switching[](https://stackoverflow.com/questions/52524112/how-do-i-install-java-on-mac-osx-allowing-version-switching) – Anar Xocayev Dec 11 '21 at 09:19
  • @AnarXocayev - The link in your comment is broken ... – Stephen C Dec 11 '21 at 09:42
  • @StephenC, yours is perfect answer that link has solved my problem. – Madasu K Dec 11 '21 at 10:23

1 Answers1

8
  1. List all Java versions installed on your Mac.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    11.0.11 (x86_64) "Oracle Corporation" - "Java SE 11.0.11" /Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home
    1.8.241.07 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_241 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
  1. Set Desired version to JAVA_HOME environment variable.
export JAVA_HOME=`/usr/libexec/java_home -v 11.0.11`
  1. Update the .bashrc or .zshrc file in your ~ Home directory.
vi ~/.zshrc

Add/Edit this line in the file and Save.

export JAVA_HOME=$(/usr/libexec/java_home -v 11.0.11)
  1. Open a New window in Terminal and verify if it worked.
$ java -version
java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)
bellam
  • 154
  • 4