How to Install Java 21 on macOS

With the release of Java 21, developers around the globe are eager to upgrade and leverage the new features it brings. If you're a macOS user, this guide will provide you with a streamlined process to get Java 21 up and running on your device.

Why Upgrade to Java 21? 

Before diving into the installation steps, let's briefly touch on why you'd want to upgrade: 

Enhanced Performance: Java 21 promises better performance, ensuring your applications run faster and smoother. 

New Features: Every new Java release introduces features that simplify development and enhance functionality. 

Security: Regularly updating Java ensures you are protected from identified vulnerabilities.


  • A macOS device.
  • Internet connection to facilitate the software download.

Installation Steps

1. Navigate to Java's Official Website:

Begin by heading to the JDK Development Kit 21.0.1 downloads.

2. Choose macOS Installer:

Identify the download labeled as x64 DMG Installer. Click on it to initiate the download process.

How to Install Java on MacOS

3. Run the Downloaded .dmg File:

Once the download is complete, locate the .dmg file, and double-click to run the installer.

4. Adhere to the Installation Guide:

The Java installer will pop up with clear steps. Stick with the default settings and proceed by clicking "Next" until the installation concludes.

5. Confirm the Installation:

To ensure Java 21 is installed correctly, open the Terminal and type: java -version. If the response indicates Java 21, the installation was successful.

6. Setting JAVA_HOME on macOS (Recommended) 

For some applications, you'll need to set the JAVA_HOME environment variable: 

In Terminal, type:

echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 21)' >> ~/.zshrc

Then, apply the changes: 

source ~/.zshrc

Congratulations! You have now equipped your macOS device with Java 21. Get started with your next big Java project today!

Reference Links