-
Notifications
You must be signed in to change notification settings - Fork 0
Install OpenJDK
Zhamri Che Ani edited this page Nov 19, 2025
·
11 revisions
brew update
brew install openjdk@21
macOS does not automatically link newer JDKs, so you must link it manually:
brew link --force --overwrite openjdk@21
If Homebrew refuses to link, use this alternative:
sudo ln -sfn /usr/local/opt/openjdk@21/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-21.jdk
(Use /opt/homebrew instead of /usr/local if you're on Apple Silicon.)
Add this to your shell config.
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 21)"' >> ~/.zshrc
source ~/.zshrc
echo 'export JAVA_HOME="$(/usr/libexec/java_home -v 21)"' >> ~/.bash_profile
source ~/.bash_profile
java -version
Expected output:
openjdk version "21" 2023-09-19