Java

There is no AI here. All content is human-authored and tested for accuracy.

Uninstall Java on Mac

Uninstall Java on Mac. macOS uninstall for JDKs, files, caches, and shell configuration. Clean up Homebrew, delete Oracle files, and verify Java removal.

This guide shows you how to uninstall Java fully and carefully from your Mac. You will learn how to remove JDK and JRE installations, delete leftover files, and verify that Java is gone. The instructions cover removal for Java installed with vendor PKGs, Homebrew uninstallation, and cleanup for Oracle-specific components.

The process differs depending on whether you installed Java manually, via Homebrew, or through a version manager like SDKMAN or mise. Java installations on Mac leave files across multiple system locations. A complete uninstallation may require removing the main JDK directories, vendor-specific components, cached files, and shell configuration entries. This guide covers everything you need to know.

For more articles, including how to Download Java for Mac and Install Java on Mac, see the Java on Mac introduction.

Before you get started

You'll need a terminal application to uninstall Java from 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 Uninstall Java

Developers commonly uninstall Java for these reasons:

  • Remove old versions: Multiple JDK versions accumulate over time, causing version conflicts. Installing a new JDK on Mac does not remove old versions. The old versions remain in place, with potential for confusion or conflict.

  • Free disk space: A single JDK installation takes 300-500MB. Multiple versions plus caches can consume several gigabytes.

  • Security concerns: Older Java versions contain known vulnerabilities. Removing unused Java eliminates potential attack vectors.

  • Troubleshooting issues: Misconfigured JAVA_HOME, corrupted installations, or IDEs detecting the wrong Java version often require a fresh start.

  • Clean installation: Switching distributions (for example, from Oracle JDK to Eclipse Temurin) works best with a clean slate.

  • Version conflicts: Build tools like Maven and Gradle may use unexpected Java versions when multiple JDKs are installed.

Before You Begin

Check for applications that depend on Java before removing it. Common Java-dependent tools include IntelliJ IDEA, Eclipse, Android Studio, Maven, and Gradle. Removing Java will break these applications until you reinstall.

Document Your Current Setup

Save your current Java configuration before making changes. This helps if you need to restore settings later. Learn How to Open Terminal in Mac and run:

$ /usr/libexec/java_home -V > ~/java-backup-info.txt
$ echo "JAVA_HOME: $JAVA_HOME" >> ~/java-backup-info.txt

Find Installed Java Versions

Before removing Java, identify what is installed and where it came from. Different installation methods require different removal approaches.

List All Java Installations

The java_home utility shows every JDK registered with macOS. Run this command to see all installed versions:

$ /usr/libexec/java_home -V

The output shows version numbers, architectures (arm64 for Apple Silicon, x86_64 for Intel), and installation paths.

Check the JDK Directory

List the contents of the primary Java installation folder:

$ ls -la /Library/Java/JavaVirtualMachines/

Each .jdk folder represents an installed version. Folder names indicate the vendor and version (for example, temurin-25.jdk or jdk-21.0.3.jdk).

Check for Homebrew Installations

If you use Homebrew, check for Java packages installed as formulas or casks:

$ brew list --formula | grep -E 'openjdk|java'
$ brew list --cask | grep -E 'temurin|zulu|corretto|oracle|java'

Homebrew formula installations (like openjdk) install to the Homebrew Cellar and you must add symlinks manually. See Brew Install Java - Formula Method. Homebrew cask installations (like temurin) install to the Homebrew Caskroom and automatically create symlinks for JDKs in /Library/Java/JavaVirtualMachines/. See Brew Install Java - Easy Cask Method.

Uninstall Java with Homebrew

If you installed Java through Homebrew, use Homebrew commands to remove it. This approach is cleaner than manual deletion because Homebrew tracks the files it installed.

Uninstall Formulas

Remove specific OpenJDK versions. You might have some of these versions:

$ brew uninstall openjdk
$ brew uninstall openjdk@25
$ brew uninstall openjdk@21
$ brew uninstall openjdk@17

To force-remove all OpenJDK versions at once:

$ brew uninstall --force openjdk

Uninstall Casks

Remove vendor JDKs installed as casks. The --cask flag is required for cask packages. You might have some of these distributions:

$ brew uninstall --cask temurin
$ brew uninstall --cask temurin@25
$ brew uninstall --cask zulu
$ brew uninstall --cask corretto
$ brew uninstall --cask oracle-jdk

Batch Uninstall All Homebrew Java

To remove all Homebrew-managed Java packages at once, use this loop. Review the package list first before running.

$ brew list | grep -E 'java|jdk|openjdk|temurin|zulu|corretto'

If the list looks correct, run the uninstall loop:

$ for pkg in $(brew list | grep -E 'java|jdk|openjdk|temurin|zulu|corretto'); do
    brew uninstall "$pkg"
done

Clean Up After Homebrew Uninstall

Run cleanup commands to remove cached downloads and orphaned dependencies:

$ brew cleanup
$ brew autoremove

See Housekeeping for Homebrew for more on how to keep Homebrew and its packages up to date.

Remove Stale Symlinks

Homebrew formula installations create symlinks that may persist after uninstallation. Remove any remaining symlinks:

$ sudo rm -f /Library/Java/JavaVirtualMachines/openjdk*.jdk

Check for leftover symlinks in the Homebrew opt directory:

$ ls -la /opt/homebrew/opt/ | grep openjdk

On Intel Macs, check /usr/local/opt/ instead of /opt/homebrew/opt/.

Manual Uninstallation

Use manual removal for Java installed from Oracle downloads, vendor installers, or any method other than Homebrew. This approach gives you precise control over what gets deleted.

Navigate to the JDK Directory

Open a terminal application and change to the Java installation folder:

$ cd /Library/Java/JavaVirtualMachines
$ ls

You will see one or more folders ending in .jdk. Each folder is a separate Java installation.

Remove a Specific Version

Delete a specific JDK by its exact folder name. Use Tab completion to avoid typos.

$ sudo rm -rf /Library/Java/JavaVirtualMachines/temurin-25.jdk

Replace temurin-25.jdk with the actual folder name shown by ls. The sudo command is required because /Library/ is a system directory owned by root.

Remove All Java Versions

To delete every JDK at once, use a wildcard. Double-check the path before pressing Enter.

$ sudo rm -rf /Library/Java/JavaVirtualMachines/*

Warning: The wildcard (*) deletes everything in this directory. Make sure you want to remove all Java installations.

Understanding sudo rm -rf

The sudo command grants administrator privileges required for system directories. Enter your Mac password when prompted (you will not see characters as you type). The -rf flags mean recursive (delete directories and contents) and force (no confirmation prompts).

When sudo is required:

  • System directories (/Library/*) require sudo because they are owned by root
  • User directories (~/Library/*) do not require sudo

Remove Oracle-Specific Components

Oracle Java installations include additional components beyond the JDK folder. Java 8 in particular installs browser plugins, preference panes, and auto-update services. JDK 11 and later simplified this, but older Oracle installations need extra cleanup.

Remove Browser Plugin and Preference Pane

Oracle's official uninstall instructions include these commands:

$ sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
$ sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane

The backslash escapes the space in "Internet Plug-Ins." Removing the preference pane eliminates the Java icon from System Settings.

Stop and Remove Update Services

Oracle installs background services for automatic updates. Unload them before deletion:

$ sudo launchctl unload /Library/LaunchAgents/com.oracle.java.Java-Updater.plist 2>/dev/null
$ sudo launchctl unload /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist 2>/dev/null

Then remove the service files:

$ sudo rm -f /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
$ sudo rm -f /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist

Remove Helper Tools and System Preferences

Oracle's privileged helper tool and system-level preference files:

$ sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
$ sudo rm -f /Library/Preferences/com.oracle.java.Helper-Tool.plist

Remove User-Level Oracle Files

These files are in your home directory and do not require sudo:

$ rm -rf ~/Library/Application\ Support/Oracle/Java
$ rm -f ~/Library/Preferences/com.oracle.java.JavaAppletPlugin.plist
$ rm -f ~/Library/Preferences/com.oracle.javadeployment.plist
$ rm -rf ~/Library/Caches/com.oracle.java.*
$ rm -rf ~/Library/Caches/Java/
$ rm -rf ~/Library/Saved\ Application\ State/net.java.openjdk.cmd.savedState

Complete Oracle Cleanup Reference

Here is a summary of all Oracle-specific files and their locations:

  • /Library/Java/JavaVirtualMachines/jdk*.jdk – Main JDK installation
  • /Library/Internet Plug-Ins/JavaAppletPlugin.plugin – Browser plugin
  • /Library/PreferencePanes/JavaControlPanel.prefPane – System Settings pane
  • /Library/LaunchAgents/com.oracle.java.Java-Updater.plist – Update agent
  • /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist – Update daemon
  • /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper – Privileged helper
  • /Library/Preferences/com.oracle.java.Helper-Tool.plist – System preferences
  • ~/Library/Application Support/Oracle/Java – Cached data
  • ~/Library/Preferences/com.oracle.java.* – User preferences
  • ~/Library/Caches/com.oracle.java.* – Cache files

Remove Installer Receipts

Oracle's pkg installer creates receipt files that track installed packages. These receipts can cause problems when reinstalling Java. The installer may refuse to install an "older" version if it finds receipts from a newer one.

List Java-Related Receipts

Check for existing receipts:

$ ls /var/db/receipts/ | grep -i oracle
$ ls /var/db/receipts/ | grep -i java

Remove Oracle Receipts

Delete the receipt files:

$ sudo rm -f /var/db/receipts/com.oracle.jdk*
$ sudo rm -f /var/db/receipts/com.oracle.jre*

Removing receipts ensures a clean slate for future Java installations.

Clean Shell Configuration

Your shell configuration files may contain JAVA_HOME exports or PATH modifications that reference removed Java installations. These entries cause errors after uninstallation.

Search all common shell configuration files for Java-related lines:

$ grep -n "JAVA_HOME\|java\|jdk" ~/.zshrc ~/.zprofile ~/.bash_profile ~/.bashrc 2>/dev/null

The -n flag shows line numbers for easier editing. Open your shell configuration file (usually ~/.zshrc or ~/.zprofile on modern Macs) and remove any lines that set JAVA_HOME or add Java to your PATH. Save the file and reload the configuration with source ~/.zshrc or source ~/.zprofile.

See the articles Mac Shell Configuration and Set Mac Path for complete instructions.

Read Set JAVA_HOME on Mac for details on configuring JAVA_HOME after reinstalling Java.

Version Manager Cleanup

If you use a Java version manager, additional cleanup is required. Version managers store Java installations in separate locations and use shims that persist after manual JDK removal.

Read Java Version Managers for details on managing multiple Java versions with SDKMAN, jEnv, and other tools.

SDKMAN

SDKMAN stores Java versions in ~/.sdkman/candidates/java/. Use SDKMAN commands to uninstall versions:

$ sdk list java
$ sdk uninstall java 25.0.1-tem

To remove SDKMAN completely:

$ rm -rf ~/.sdkman

After removing SDKMAN, edit ~/.zshrc to remove the initialization lines:

# Remove these lines:
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"

jEnv

jEnv stores shims and configuration in ~/.jenv/. After manually removing a JDK, jEnv's shims may still reference deleted paths.

List jEnv-managed versions:

$ jenv versions

Remove a version from jEnv tracking:

$ jenv remove 25.0

The jenv remove command only unregisters the version from jEnv. It does not delete the actual JDK files. You must separately remove the JDK from /Library/Java/JavaVirtualMachines/.

To remove jEnv completely:

$ rm -rf ~/.jenv

Then remove jEnv initialization from ~/.zshrc.

Other Version Managers

jabba: Stores Java in ~/.jabba/jdk/. Remove with jabba uninstall <version> or delete ~/.jabba/ entirely.

asdf: Uses ~/.asdf/installs/java/. Remove with asdf uninstall java <version> or remove the plugin with asdf plugin remove java.

Verify Uninstallation

After removing Java, verify that the uninstallation succeeded. Run these commands to confirm Java is completely gone.

Check Java Version

$ java -version

You should see: "The operation couldn’t be completed. Unable to locate a Java Runtime." This message indicates successful removal. It comes from the macOS Java system launcher, not from an actual Java installation.

List Installed JVMs

$ /usr/libexec/java_home -V

Expected output: "Unable to locate a Java Runtime." or no output at all.

Check JAVA_HOME

$ echo $JAVA_HOME

Expected output: Empty (no output). If you see a path, you still have JAVA_HOME set in your shell configuration.

Check the JDK Directory

$ ls /Library/Java/JavaVirtualMachines/

Expected output: Empty directory or only the versions you intended to keep.

Clear Shell Hash Cache

If java -version still shows the old version immediately after removal, your shell may have cached the command path. Clear the cache:

$ hash -r

Alternatively, open a new terminal window. The new session will not have cached paths.

Troubleshooting

Java Still Appears After Uninstall

If java -version still shows a version number after following this guide:

  1. Multiple versions exist: Run /usr/libexec/java_home -V to list remaining JVMs and remove them.

  2. Shell configuration issue: Search for lingering JAVA_HOME exports:

    $ grep -n "JAVA_HOME\|java\|jdk" ~/.zshrc ~/.zprofile ~/.bash_profile ~/.bashrc 2>/dev/null
    
  3. Version manager shims: If using SDKMAN, jEnv, jabba, or asdf, their shims may still be active. Reconfigure or remove these tools.

  4. Shell cache: Clear the hash table with hash -r or open a new Terminal window.

Permission Denied Errors

Use sudo for commands that modify system directories (/Library/*). If you still see "Permission denied," check that Terminal has Full Disk Access in System Settings → Privacy & Security → Full Disk Access.

Operation Not Permitted

This error can occur with locked files. Check file flags and remove immutable attributes:

$ ls -lO /path/to/file
$ sudo chflags -R nouchg /path/to/folder

Resource Busy

Kill running Java processes before removing files:

$ killall java 2>/dev/null
$ killall javaw 2>/dev/null

Understanding the macOS Java Stub

After successful removal, which java still returns /usr/bin/java. This is a macOS Java system launcher, not an actual Java installation. The stub is protected by System Integrity Protection and cannot be removed. Running java with no JDK installed triggers an "Unable to locate a Java Runtime" message. This is expected behavior that confirms Java was successfully removed.

Quick Reference: Complete Removal

For experienced users who want to remove all Java at once, here are consolidated commands.

Remove All JDKs and Oracle Components

$ sudo rm -rf /Library/Java/JavaVirtualMachines/*
$ sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
$ sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
$ sudo rm -f /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
$ sudo rm -f /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
$ sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
$ sudo rm -f /Library/Preferences/com.oracle.java.Helper-Tool.plist
$ sudo rm -f /var/db/receipts/com.oracle.jdk*
$ rm -rf ~/Library/Application\ Support/Oracle
$ rm -f ~/Library/Preferences/com.oracle.java.*
$ rm -rf ~/Library/Caches/com.oracle.java.*
$ rm -rf ~/Library/Caches/Java/

Verification Commands

$ java -version
$ /usr/libexec/java_home -V
$ ls /Library/Java/JavaVirtualMachines/
$ echo $JAVA_HOME

Apple Silicon vs. Intel Mac Differences

For Homebrew, the uninstallation process is identical on both Apple Silicon and Intel Macs. The only difference is Homebrew's storage directories:

  • Homebrew prefix – /usr/local/ (Intel Mac), /opt/homebrew/ (Apple Silicon Mac)
  • Formula location – /usr/local/Cellar/ (Intel Mac), /opt/homebrew/Cellar/ (Apple Silicon Mac)
  • Symlinks – /usr/local/opt/ (Intel Mac), /opt/homebrew/opt/ (Apple Silicon Mac)

The standard macOS Java location (/Library/Java/JavaVirtualMachines/) is the same on both architectures.

What's Next

After removing Java, you may want to install a fresh version. Eclipse Temurin is the recommended choice for most developers and Brew Install Java - Easy Cask Method for the simplest way to install Java on Mac.

To configure your environment after installation, see Set JAVA_HOME on Mac.

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.