How to Update Java on Windows, Mac and Linux

Updating Java means installing a newer version of the same major release (e.g. Java 21.0.1 to 21.0.3), or jumping to a new major LTS (e.g. Java 17 to Java 21). The process differs slightly by platform, but none of it requires touching your code.

Why update Java?

Minor updates (21.0.x) contain security patches for CVEs in the JDK itself, the standard library, and the cryptographic stack. Oracle and the major OpenJDK vendors release coordinated security patches every three months (the Oracle Critical Patch Update cycle). Running an unpatched JDK in production is a real risk β€” the 2021 Log4Shell incident showed how JVM-hosted apps can be vectors even when the vulnerability is in a library, not the JVM itself.

Update on Windows

If you installed via winget:

winget upgrade EclipseAdoptium.Temurin.21.JDK

Or upgrade everything at once:

winget upgrade --all

If you installed via MSI: download the newer MSI from adoptium.net and run it β€” it overwrites the previous install in place, preserving your PATH and JAVA_HOME settings.

Update on macOS

brew upgrade openjdk@21

After upgrading, re-run the symlink command if Homebrew prints one. Verify:

java -version

If you installed via .pkg: download the new .pkg from adoptium.net, run it β€” it upgrades in place.

Update on Ubuntu/Debian

sudo apt update
sudo apt upgrade openjdk-21-jdk

Or upgrade all packages: sudo apt upgrade.

Update on Fedora/RHEL

sudo dnf update java-21-openjdk-devel

Major version upgrade (e.g. Java 17 to Java 21)

This is not an in-place update β€” install the new version side by side, then switch:

  1. Install Java 21 (see platform-specific install guides).
  2. Run your test suite with Java 21 β€” check for deprecated API warnings turned hard errors, and for removed internal APIs (sun.*).
  3. Update your build file to target Java 21.
  4. Switch JAVA_HOME and PATH (or update project SDK in your IDE).
  5. Uninstall Java 17 only after the migration is confirmed stable.

Check the current version after update

java -version

The version number should reflect the new build.