You know, JDK 21 is the latest Long Term Support (LTS) release of Java SE platform as of December 2023. In this article, I’d like to share how to setup Oracle JDK - a commercial distribution of JDK - on Mac computer, so you can develop, build and run Java applications on macOS.

 

1. Download Oracle JDK 21 Installer for macOS

The first step of setting up JDK on macOS is download an installer. Oracle JDK 21 is distributed as compressed archive and DMG installer for macOS. Head over to the official Java Downloads page and you will see the following page:

Java Downloads JDK 21 macOS

It’s recommended to use DMG Installer as it makes the setup convenient. Click one of the following download link:

  • ARM64 DMG Installer: download this if your Mac is equipped with Apple silicon (Apple’s CPU)
  • x64 DMG Installer: download this if your Mac uses Intel’s CPU (probably old Mac)
Then it’s strongly recommended to verify the integrity of the downloaded .dmg file before opening it, to ensure that the file is not tampered with malicious code. Open a new Terminal window, then change the current directory to the folder that contains the .dmg file. And type the following command:

shasum -a 256 jdk-21_macos-aarch64_bin.dmg

This command prints SHA256 checksum value of the specified file. Compare this checksum value against the one published on the download page (click link number 2 above). If they’re the same, it’s safe to run the DMG installer.

 

2. Install Oracle JDK 21 on macOS

Now, to install Oracle JDK 21 on macOS, double click the DMG file. A JDK package will be shown. Then double click the package to launch JDK 21 installer, as shown below:



JDK 21 installer on macos

Click Continue to proceed the installation with default configuration. It will take just a few seconds to complete the setup.

It will install Oracle JDK 21 under the/Library/Java/JavaVirtualMachines/jdk-21.0.1.jdk directory. The installer puts java and javac executables under/usr/bin directory, which is included in the PATH environment variable. So you don’t have to manually configure environment variable.

To verify, open a new Terminal window and type the following commands:

  • java -version: to check version of Java virtual machine.
  • javac -version: to check version of Java compiler
You should see the following output:

check version of java and javac 21

This means Oracle JDK 21 has been installed properly on macOS. Now, you can create, develop, build and run Java applications on your Mac computer.

To see the setup in action, watch the following video:

 

Related Articles:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment