Update Java on Mac
Why update Java on macOS. How to upgrade Java on Mac. Update Java versions using Homebrew or installers. How to check and verify updates.
Java does not update automatically on macOS. You need to check for updates and apply them yourself. Security patches are available at least four times a year, in January, April, July, and October.
This guide covers updating an existing Java installation. If you need to install Java from scratch, see Download Java for Mac instead.
Before you get started
You'll need a terminal application to update and develop with Java on your Mac. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and makes coding easier when working with Java.
Why Update Java
Keeping Java current protects your system and improves performance. Here's why updates matter.
Security Patches
Java security patches address CVEs (Common Vulnerabilities and Exposures) that attackers can exploit. Hopefully you never encountered the Log4Shell vulnerability in 2021 but it demonstrates how serious these risks can be. It affected millions of Java applications and enabled remote code execution with a CVSS score of 10.0 (critical).
Recent vulnerabilities include:
- CVE-2024-20952: Remote attackers could compromise confidentiality and integrity
- CVE-2024-20918: Unauthorized access to critical data through VM vulnerabilities
- CVE-2024-21011: Networking vulnerabilities patched in April 2024
Running outdated Java exposes you to known exploits. It's best to update within 2-3 weeks of each quarterly release.
Java Performance Improvements
Real-world migrations show measurable gains:
- Java 11 → Java 21 – 50% fewer long requests
- Java 21 → Java 25 – 12% faster startup
- Various benchmarks – Up to 37% faster overall
Java 25 introduced compact source files (simplified void main() syntax), flexible constructor bodies, scoped values for virtual threads, compact object headers for 22% memory savings, and improved garbage collection performance.
Bug Fixes and New Features
Quarterly updates fix memory leaks, threading issues, and platform-specific bugs. Major version upgrades bring new language features that make your code more expressive and maintainable.
Framework Requirements
Modern frameworks require recent Java versions. Spring Boot 3.x requires Java 17 minimum. Staying current ensures compatibility with the tools you depend on.
Security Update Schedule
Oracle releases Critical Patch Updates (CPU) quarterly on a predictable schedule:
- Third Tuesday of January
- Third Tuesday of April
- Third Tuesday of July
- Third Tuesday of October
Eclipse Adoptium releases Temurin builds 1-2 weeks after each Oracle CPU.
Apply security patches within 2-3 weeks of release. For critical CVEs, update immediately.
LTS Support Timeline
- Java 8 – End of free updates December 2030
- Java 11 – End of free updates January 2032
- Java 17 – End of free updates September 2029
- Java 21 – End of free updates December 2029
- Java 25 – End of free updates September 2033
Stick to LTS versions for production. Avoid non-LTS versions (22, 23, 24, 26) unless you're prepared to upgrade every 6 months.
Read Compare Java 21 to Java 25 for a detailed comparison between the two newest LTS versions.
Update vs Upgrade Terminology
The terms "Java update" and "Java upgrade" appear similar but have distinctly different meanings. A Java update is a minor revision—like Java 25.0.1 to 25.0.2—that delivers bug fixes and security patches without changing functionality. A Java upgrade, on the other hand, is a major version jump—like Java 21 to Java Tahoe 25—with new features and functionality. This guide covers both.
- Update (or patch): Stay on the same major version, apply security fixes (25.0.1 → 25.0.2)
- Upgrade: Move to a new major version with new features (21 → 25)
Patch updates are low-risk and should be applied promptly. Major upgrades require testing and may involve breaking changes.
Where is the JDK?
The process for updating Java depends on how you installed the Java JDK. Depending on how you installed Java, there are four or more likely locations for Java and different commands needed to update Java.
Brew Install Java - Easy Cask Method — Update with brew upgrade --cask temurin@21 (or your installed cask name). The Homebrew cask method installs a JDK using a symlink so that it appears under /Library/Java/JavaVirtualMachines/temurin-25.jdk/, the standard Java location on macOS. The bundle ultimately resolves via symlinks into Homebrew’s own cask storage under the Caskroom (for example, /opt/homebrew/Caskroom or /usr/local/Caskroom, depending on whether you hava an Apple Silicon or Intel Mac).
Brew Install Java - Formula Method — Update with brew upgrade openjdk@21. The Homebrew formula method installs OpenJDK to the Homebrew Cellar (/opt/homebrew/Cellar/ on Apple Silicon or /usr/local/Cellar/ on Intel). After upgrading, recreate the symlink to /Library/Java/JavaVirtualMachines/ if the version changed.
Version Manager (SDKMAN, mise, jEnv) — Version managers install JDKs to their own directories (~/.sdkman/candidates/java/ for SDKMAN, ~/.local/share/mise/installs/java/ for mise). Update by installing the new version through your version manager, then set it as default.
Manual PKG Installer — If you downloaded a .pkg or .dmg installer, the JDK lives in /Library/Java/JavaVirtualMachines/. Update by downloading and running the latest installer from the vendor's website.
Check Your Current Java Version
Before updating, confirm which Java version you have installed. Learn How to Open Terminal in Mac and run:
$ java -version
You should see output showing your version number, like 25.0.1 for Java 25 patch level 1. The vendor name (Homebrew, Temurin, or Oracle) tells you which distribution you have installed. Read Check Java Version on Mac for detailed version checking instructions and understanding version numbers.
To list all installed JDKs on your Mac:
$ /usr/libexec/java_home -V
Check for Updates
Compare your installed version against the latest releases. If your version number is lower than the current release, an update is available.
For Homebrew cask installations, check for outdated packages with brew outdated --cask. For Homebrew formula installations, check with brew outdated --formula.
For JDKs installed from a vendor PKG, check the vendor website for updates as listed at Download Java for Mac.
For JDKs installed using a Java version manager, try sdk list java for SDKMAN or mise ls-remote java for mise.
Java Updates via Homebrew Cask
The Homebrew cask method is the easiest way to install and update Java on Mac. Homebrew handles downloads, installation, and cleanup automatically. The Temurin cask is the most popular, illustrated here. Read Brew Install Java - Easy Cask Method for the initial Homebrew installation details.
One-Command Update
For the fastest update, run this combined command:
$ brew update && brew upgrade --cask temurin && brew cleanup
This fetches the latest package definitions, upgrades Temurin to the newest version, and removes old cached files.
Step-by-Step Update
If you prefer to see what's happening at each stage:
Step 1: Update Homebrew's package database.
$ brew update
Step 2: Check which packages have updates available.
$ brew outdated --cask
If temurin or your specific version appears, continue to the next step.
Step 3: Upgrade Java.
For the latest Temurin (recommended):
$ brew upgrade --cask temurin
For a specific version:
$ brew upgrade --cask temurin@25
Step 4: Clean up old versions.
$ brew cleanup
This removes cached downloads and old package versions.
Step 5: Verify the update.
$ java -version
You should see the new version number.
If the Upgrade Fails
Sometimes upgrades fail due to corrupted downloads or permission issues. Reinstall the package:
$ brew reinstall --cask temurin
This removes and reinstalls the package cleanly.
Java Updates via Homebrew Formula
If you installed Java via the openjdk formula instead of a cask:
$ brew upgrade openjdk@25
After upgrading, recreate the symlink so macOS can find it:
$ sudo ln -sfn /opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-25.jdk
On Intel Macs, replace /opt/homebrew with /usr/local.
Java Updates for PKG installations
If you downloaded and installed Java manually with a vendor PKG, you can install again using a newer PKG version. To illustrate, here's an update process for the popular Temurin distribution.
Visit a Vendor's Website
Visit a vendor's website to download a JDK:
- Eclipse Temurin: adoptium.net
- Azul Zulu: azul.com/downloads
- Amazon Corretto: aws.amazon.com/corretto
- Microsoft OpenJDK: learn.microsoft.com
- BellSoft Liberica: bell-sw.com
Download the Latest Version
For example, for the Temurin distribution:
- Go to https://adoptium.net/temurin/releases/
- Select macOS as the operating system
- Select aarch64 for Apple Silicon (or x64 for Intel)
- Select JDK as the package type
- Choose PKG as the file type
- Click to download
The PKG installer is recommended because it handles all configuration automatically.
Verify the Download (Optional)
Check the file integrity before installing:
$ shasum -a 256 ~/Downloads/OpenJDK25U-jdk_aarch64_mac_hotspot_25.0.1_7.pkg
Compare the output against the checksum on the download page.
Run the Installer
- Double-click the downloaded PKG file
- Click Continue through the introduction
- Review and accept the license agreement
- Click Install
- Enter your administrator password when prompted
- Wait for installation to complete
- Click Close
The installer places the JDK in /Library/Java/JavaVirtualMachines/. Patch updates (like 25.0.1 to 25.0.2) replace the existing version. Major version installs (like adding Java 25 alongside Java 21) preserve both versions.
Handling Gatekeeper Warnings
If macOS shows "cannot be opened because the developer cannot be verified":
- Right-click (or Control-click) the installer file
- Select Open from the context menu
- Click Open in the confirmation dialog
This is rare with official distributions from Adoptium, Oracle, or Azul since they're signed and notarized.
Verify the Installation
$ java -version
You should see the new version number. For JDKs in /Library/Java/JavaVirtualMachines/, the Java system launcher chooses the newest Java release. See Set JAVA_HOME on Mac to set a different version as a default.
Update Multiple Java Versions
If you have multiple Java versions installed, you can update each one independently with Homebrew. Use version-specific casks like temurin@25 and temurin@21 to control exactly which versions you update. Use jEnv with Homebrew if you need lightweight switching among Homebrew-installed JDKs. See Java Version Managers on Mac.
Alternatively, SDKMAN for Java on Mac simplifies managing and updating multiple Java versions. It handles installation, switching, and updates with simple commands. This is especially useful if you work on projects requiring different Java versions.
Post-Update Configuration
After updating Java, you may need to update your JAVA_HOME environment variable. Check its current value with echo $JAVA_HOME. If it points to an old path, update it in your shell configuration file. Read Set JAVA_HOME on Mac for detailed environment configuration.
For dynamic version detection that always points to the latest installed version, add this to your ~/.zprofile file:
export JAVA_HOME=$(/usr/libexec/java_home)
Reload your shell with source ~/.zprofile and verify with echo $JAVA_HOME. See the article Mac Shell Configuration for complete instructions.
Remove Old Java Versions
After confirming the new version works correctly, you can remove old versions to free disk space. For Homebrew installations, use brew uninstall --cask temurin@21 (for example). For manual installations, remove the JDK folder from /Library/Java/JavaVirtualMachines/.
Keep old versions installed for 2-4 weeks after upgrading as a safety net before removing them.
Read Uninstall Java on Mac for complete removal instructions.
Troubleshooting
Old Version Still Shows After Update
Problem: java -version shows the old version even after updating.
Cause: Your JAVA_HOME or PATH points to the old installation.
Solution:
Check what Java executable is being used:
$ type -a java
Update JAVA_HOME to use the dynamic resolver:
$ export JAVA_HOME=$(/usr/libexec/java_home)
Add this to your ~/.zprofile and reload with source ~/.zprofile.
Apple "Install Java" Dialog Appears
Problem: macOS shows a dialog saying "To use the java command-line tool you need to install a JDK."
Cause: The system doesn't detect your installed JDK. This prompts you to install Apple's legacy Java 6.
Solution: Do NOT install the legacy Java 6—it's outdated and insecure.
See Download Java for Mac instead.
Permission Errors During Update
Problem: Installation fails with "permission denied."
Solution:
For Homebrew, fix permissions:
$ sudo chown -R $(whoami) /opt/homebrew
For PKG installers, ensure you have administrator access and enter your password when prompted.
Homebrew Symlink Issues
Problem: System doesn't detect Homebrew-installed OpenJDK.
Solution: Create the symlink manually:
$ sudo ln -sfn /opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-25.jdk
Verify it worked:
$ /usr/libexec/java_home -V
Conflicting Versions Causing Problems
Problem: Different tools use different Java versions unexpectedly.
Solution: Use a version manager to control which version each tool sees. Or remove versions you don't need:
$ sudo rm -rf /Library/Java/JavaVirtualMachines/temurin-21.jdk
IDE Not Recognizing New Version
Problem: Your IDE still uses the old Java version.
Solution:
- IntelliJ: File → Invalidate Caches → Invalidate and Restart
- Eclipse: Eclipse → Preferences → Java → Installed JREs → Add the new JDK
- VS Code: Run "Java: Clean Java Language Server Workspace" from Command Palette
Gatekeeper Blocks Downloaded Installer
Problem: "Cannot be opened because the developer cannot be verified."
Solution: Right-click the installer, select Open, then click Open in the dialog.
Quick Reference
Essential Commands
# Check Java version
java -version
# List all installed JDKs
/usr/libexec/java_home -V
# Check JAVA_HOME
echo $JAVA_HOME
# Update via Homebrew (recommended)
brew update && brew upgrade --cask temurin && brew cleanup
# Check for outdated Homebrew casks
brew outdated --cask
# Set JAVA_HOME dynamically
export JAVA_HOME=$(/usr/libexec/java_home)
# Set JAVA_HOME to specific version
export JAVA_HOME=$(/usr/libexec/java_home -v 25)
# Create symlink for OpenJDK formula
sudo ln -sfn /opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-25.jdk
# Remove old JDK manually
sudo rm -rf /Library/Java/JavaVirtualMachines/temurin-21.jdk
Update Workflow Summary
For routine quarterly updates using Homebrew:
java -version— Check current versionbrew update && brew outdated --cask— Check for updatesbrew upgrade --cask temurin— Apply updatejava -version— Verify new version- Test your applications
For major version upgrades:
- Run compatibility analysis (
jdeps,jdeprscan) - Install new version alongside old one
- Update project configurations
- Run full test suite
- Update
JAVA_HOMEand IDE settings - Monitor for issues
- Remove old version after 2-4 weeks
What's Next
Now that your Java installation is up to date:
- Update your build tools — Ensure Maven and Gradle configurations target the correct Java version
- Explore new features — Java 25 introduced compact source files, flexible constructors, scoped values, and compact object headers for improved memory efficiency
My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.