Safeguard
DevSecOps

How to Uninstall Java Safely on Windows, macOS, and Linux

To uninstall Java cleanly you need to remove the runtime, clear leftover paths and environment variables, and confirm nothing critical still depends on it.

Marcus Chen
DevSecOps Engineer
6 min read

To uninstall Java properly you remove the JRE or JDK through your operating system's normal package or uninstall mechanism, then clean up the leftover paths and environment variables so no stale runtime lingers on the machine. People usually want to uninstall Java for one of two reasons: they no longer need it, or they're removing an old, unpatched version that's a security liability. Either way, a clean removal matters, because a forgotten legacy Java runtime is a classic quiet attack surface — think back to how many browser and desktop compromises rode in on outdated Java plugins.

Here's how to do it cleanly on each platform, plus how to make sure you're not about to break something that depends on it.

First: check what depends on Java

Before you remove anything, confirm what's actually using Java. Removing it out from under an application that needs it is an easy way to create an outage.

java -version

On many systems, applications like build tools, some databases, Android tooling, and enterprise desktop apps bundle or require a JRE. If you find a dependency, consider updating Java to a current, supported release instead of removing it — an out-of-date Java is the risk, and a patched one is fine. If nothing depends on it, proceed.

Also decide which Java you're removing. Many machines have several: a system JRE, one or more JDKs installed by developers, and versions bundled inside applications. You often want to remove the standalone installs while leaving app-bundled runtimes alone.

Uninstalling Java on Windows

Oracle Java and OpenJDK builds installed via an MSI show up in the standard uninstaller.

  1. Open Settings, go to Apps, then Installed apps (or Control Panel, Programs and Features on older Windows).
  2. Find entries like "Java 8 Update xxx", "Java SE Development Kit", or a vendor OpenJDK build.
  3. Select each and choose Uninstall. Remove every version you don't need.

After uninstalling, clean up leftovers:

  • Delete stale install folders under C:\Program Files\Java\ and C:\Program Files (x86)\Java\ if they remain.
  • Remove JAVA_HOME if it points at the removed version (System Properties, Environment Variables).
  • Edit the Path variable and delete any entry pointing to the old \bin directory.

Oracle also publishes a Java Uninstall Tool that removes older versions; it's useful when you have a pile of accumulated Java 8 updates. Reboot afterward so environment changes take effect, then confirm with java -version in a fresh terminal — you want "command not found" or your intended remaining version.

Uninstalling Java on macOS

How you remove it depends on how it was installed.

Homebrew installs:

brew uninstall openjdk        # or the specific formula, e.g. openjdk@17

Oracle JDK / manual installs live under /Library/Java/JavaVirtualMachines/. Each version is its own directory:

# list installed JVMs
/usr/libexec/java_home -V

# remove a specific one (requires admin)
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-17.jdk

Also remove the old Java plugin and preferences if present under /Library/Internet Plug-Ins/ and /Library/PreferencePanes/. macOS picks the active JDK dynamically, so after removal run /usr/libexec/java_home -V again to confirm what's left, and check your shell profile (.zshrc, .bash_profile) for a JAVA_HOME export pointing at something you deleted.

Uninstalling Java on Linux

Use your package manager for anything installed that way.

Debian/Ubuntu:

# see what's installed
dpkg --list | grep -i jdk
dpkg --list | grep -i jre

sudo apt remove --purge openjdk-17-jdk openjdk-17-jre
sudo apt autoremove

RHEL/Fedora/CentOS:

rpm -qa | grep -i jdk
sudo dnf remove java-17-openjdk java-17-openjdk-headless

If you installed Java manually by extracting a tarball, just delete the directory and remove the alternatives entries and any PATH/JAVA_HOME exports in /etc/profile.d/ or user shell files:

sudo update-alternatives --remove java /opt/jdk-17/bin/java

Confirm with which java and java -version.

Clean up the environment everywhere

The part people forget is the environment, and a dangling JAVA_HOME or PATH entry causes confusing "command not found" or wrong-version errors later. On every platform, after removing the binaries:

  • Remove or repoint JAVA_HOME.
  • Strip old Java bin directories from PATH.
  • Clear per-user caches (the old .java directory in your home folder) if you want a truly clean slate.

The security angle

The reason this matters beyond tidiness: an unpatched Java runtime sitting unused on a machine is dead weight that still carries live vulnerabilities. Removing software you don't use is one of the simplest attack-surface reductions available — there's nothing to exploit if it isn't installed. If you do need Java, the right move isn't removal but disciplined patch management: track which version is deployed and keep it current. For the applications that ship Java libraries rather than the runtime, an SCA tool such as Safeguard inventories the Java dependencies inside your builds and flags known CVEs, which complements keeping the runtime itself patched. Our AWS infrastructure as code guide covers the same reduce-what-you-don't-need principle for cloud resources.

FAQ

How do I completely uninstall Java?

Remove every JRE/JDK through your OS uninstaller or package manager, delete leftover install directories, then clean the environment by removing JAVA_HOME and stripping old Java bin paths from PATH. Confirm with java -version in a fresh terminal that only the runtime you intend (or none) remains.

Will uninstalling Java break my applications?

It can, if an app depends on it. Run java -version and check your build tools, databases, and desktop apps first. If something needs Java, update it to a current supported release rather than removing it, since the security risk is an outdated Java, not Java itself.

How do I remove old Java versions but keep the latest?

On Windows, uninstall the specific old entries in Installed apps. On macOS, rm -rf the specific directory under /Library/Java/JavaVirtualMachines/. On Linux, remove the specific package (e.g. openjdk-8-jre) while leaving the current one installed. Then confirm the active version with java -version.

Why is uninstalling unused Java a security best practice?

An unused, unpatched runtime still carries exploitable vulnerabilities but gets no attention or updates. Removing software you don't use eliminates that attack surface entirely. If you need Java, keep it patched instead; the danger is stale, forgotten versions.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.