How to Update Java on Mac
Update Java on Mac by running brew upgrade (if you used Homebrew) or downloading and running a new .pkg file from Adoptium. The update takes two minutes and does not break existing projects.
Homebrew update
brew update # refresh brew's formula index
brew upgrade openjdk@21 # upgrade to the latest 21.x patch
If you run multiple LTS versions, upgrade each explicitly:
brew upgrade openjdk@17 openjdk@21
Homebrew may print a new symlink command after upgrade. Re-run it if prompted:
sudo ln -sfn $(brew --prefix)/opt/openjdk@21/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-21.jdk
.pkg update
- Go to
adoptium.netand download the new Java 21 macOS.pkgfor your architecture (aarch64 or x64). - Double-click the
.pkgand follow the installer — it replaces the previous build. - Open a new Terminal and verify:
java -version.
Verify the update
java -version
/usr/libexec/java_home -V # list all installed JDKs
JAVA_HOME after update
If you set JAVA_HOME with a hard path (e.g. /Library/Java/JavaVirtualMachines/temurin-21.0.1.jdk/...), the patch update changes the directory name and breaks the hard path. Use the dynamic form instead:
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
This always resolves to the highest installed 21.x, regardless of patch version.
Automatic updates
Homebrew does not auto-upgrade packages. Run brew upgrade periodically or set up a cron/launchd job. For the .pkg path, some vendors offer update notifications — Temurin does not. Subscribe to adoptium.net/releases or follow the @adoptium account for release announcements.