How to install Java JDK 21 on MacBook, macOS Sonoma

Опубликовано: 07 Апрель 2026
на канале: StartQACareer
2,312
25

===== Step 0 =====

Check if it is already installed and configured, run in terminal

java -version

zsh: command not found: java

or

The operation couldn’t be completed. Unable to locate a Java Runtime.

===== Step 1 =====

Open in a browser https://www.oracle.com/java/technolog...

Exact latest available Java version number might be different depending on when you are watching this video

Click on macOS tab

download ARM64 DMG Installer if you have Apple M chip
download x64 DMG Installer if you have Intel chip

Run the file you downloaded and follow steps prompted

===== Step 2 =====

Run the command java -version in terminal again to see the output

===== Step 3 =====

Add JAVA_HOME environment variable in your terminal config file

Go to your user folder in terminal

cd ~/
open .

To see hidden files in the Finder hit keys combination: command + shift + .

Create terminal config file (if you don't already have it in your users folder)

touch .zshrc
or
touch .bash_profile - if your terminal uses bash for some reasons instead of zsh

Now we need to take the folder name for our Java installation, for that go to

cd /Library/Java/JavaVirtualMachines/

open .

In my case the folder has name "jdk-21.jdk", copy it and paste it into the line below which you will put in the config

Open .zshrc file in text editor and add into the beginning of the file

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home

Save changes in file and close it. You can use "command + s" and "command + q" key combinations.

Restart/close all terminal windows and open again to apply new configuration that you added

===== Step 4 =====

Run the command java -version in terminal again to see the output

===== Step 5 =====

Select installed JDK in your IDE project settings in File - Project Structure - Platform Settings - SDKs