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


Have Questions? Post them here!
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.