Install OpenJDK 11 on macOS

Install using HomeBrew

$ brew install --cask adoptopenjdk/openjdk/adoptopenjdk11
==> Installing Cask adoptopenjdk11
==> Running installer for adoptopenjdk11; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.

Manual Install from AdoptOpenJDK


Manual Install from

Update download url based on the latest version available in this download page:

$ cd /tmp
$ curl -O
$ tar xf openjdk-11.0.2_osx-x64_bin.tar.gz
$ sudo mv jdk-11.0.2.jdk /Library/Java/JavaVirtualMachines/

Listing Installed JDK Version

$ /usr/libexec/java_home -h
Usage: java_home [options...]
    Returns the path to a Java home directory from the current user's settings.

    [-v/--version   <version>]       Filter versions (as if JAVA_VERSION had been set in the environment).
    [-a/--arch      <architecture>]  Filter architecture (as if JAVA_ARCH had been set in the environment).
    [-F/--failfast]                  Fail when filters return no JVMs, do not continue with default.
    [   --exec      <command> ...]   Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
    [-X/--xml]                       Print full JVM list and additional data as XML plist.
    [-V/--verbose]                   Print full JVM list with architectures.
    [-h/--help]                      This usage information.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3): (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 11" /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
    11.0.2 (x86_64) "Oracle Corporation" - "OpenJDK 11.0.2" /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
    1.8.0_212 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

Switching JDK Version

Get JAVA_HOME path and set it to environment variable.

Add the following to ~/.bashrc , ~/.zshrc etc.

export JAVA_HOME=`/usr/libexec/java_home -V 2>&1 | grep 11.0.9 | grep -o '/Library/.*'`

$ /usr/libexec/java_home -V 2>&1 | grep 11.0.9 | grep -o '/Library/.*'

$ export JAVA_HOME=`/usr/libexec/java_home -V 2>&1 | grep 11.0.9 | grep -o '/Library/.*'`

$ java -version
openjdk version "" 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build
OpenJDK 64-Bit Server VM AdoptOpenJDK (build, mixed mode)


Also see:

$ jshell
|  Welcome to JShell -- Version
|  For an introduction type: /help intro

jshell> /help intro
|                                   intro
|                                   =====
|  The jshell tool allows you to execute Java code, getting immediate results.
|  You can enter a Java definition (variable, method, class, etc), like:  int x = 8
|  or a Java expression, like:  x + x
|  or a Java statement or import.
|  These little chunks of Java code are called 'snippets'.
|  There are also the jshell tool commands that allow you to understand and
|  control what you are doing, like:  /list
|  For a list of commands: /help

jshell> /exit
|  Goodbye

Leave a Comment

Your email address will not be published. Required fields are marked *