Install Java 17 (LTS) JDK on ARM based M1/M2 Mac Natively


Java 17 is the LDS - Long Term Support version released to the public in September 2021. If you want to install Java 17 JDK natively on have multiple options,

  1. Oracle JDK 17
  2. Oracle OpenJDK 17
  3. Red Hat OpenJDK 17
  4. Azul Zulu Open JDK 17
  5. Amazon Corretto OpenJDK 17

We will the installing the Oracle OpenJDK 17 using brew, it will by default pick the ARM 64 bit version.

How to install Brew on M1/M2 Mac

Brew Command:
brew install openjdk@17

==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/17/manifests/17.0.4.1
...
...
If you need to have openjdk@17 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@17 you may need to set:
  export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"
Installing JDK 17 on M1 or M2 Mac

If you want to use JDK 17 as the default, you will need to add it to the PATH in .zshrc file (both java and javac)

% echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
% export CPPFLAGS="-I/opt/homebrew/opt/openjdk@17/include"

After setting the path, you can check if it took effect by reloading the zsh shell (just type zsh on prompt) and running the version commands,

% java -version
openjdk version "17.0.4.1" 2022-08-12
OpenJDK Runtime Environment Homebrew (build 17.0.4.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.4.1+0, mixed mode, sharing)

% javac -version
javac 17.0.4.1

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap