Amazon Cyber Monday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Uninstall Java on Linux: Commands for Each Distribution

To uninstall Java on Linux, remove the Java package using your distribution’s package manager; the exact command depends on whether Java came from APT, DNF, or another installer. First check which Java is active and how it was installed, because removing one package may leave other Java versions or manually installed files in place.

Check which Java is installed

Linux systems can have multiple Java implementations and versions at once. “Java” may refer to the Java Runtime Environment (JRE), which runs Java applications, or the Java Development Kit (JDK), which also includes tools such as the compiler. OpenJDK is a widely used open-source implementation; Oracle JDK and other distributions may be installed separately.

Start by checking the active executable and version:

  • java -version prints version information if a Java runtime is available on your command path.
  • command -v java shows which executable your shell will run.
  • readlink -f "$(command -v java)" can reveal the executable’s resolved path on systems with the usual GNU tools.

To see installed packages, use your distribution’s package query tool. These commands list package names containing common Java terms, but review the results before removing anything:

  • Debian or Ubuntu: dpkg -l '*openjdk*' '*java*'
  • Fedora: rpm -qa | grep -Ei 'java|openjdk'
  • Arch Linux: pacman -Q | grep -Ei 'java|openjdk'

A missing java command does not necessarily mean no Java packages are installed. Conversely, a Java application may bundle its own runtime, which will not appear as a system-wide Java installation.

Remove Java on Debian or Ubuntu

APT-based distributions include Debian, Ubuntu, and many related systems. Find the exact package name first; examples include versioned packages such as openjdk-17-jre, openjdk-17-jdk, and their headless variants.

To remove a specific package, substitute its actual name:

  • sudo apt remove openjdk-17-jre removes that package while generally retaining its system configuration files.
  • sudo apt purge openjdk-17-jre also removes configuration files managed by that package.

If you installed a JDK, remove the JDK package as well if you no longer need it. A JDK depends on runtime components, so removing only a JRE package may not uninstall the development kit or every Java component. Use apt list --installed or the earlier dpkg query to inspect what remains.

APT may offer to remove additional packages. Read the proposed removal list before confirming: other software may depend on Java, and accepting the prompt can remove more than the Java command itself. When finished, you can run sudo apt autoremove to review and remove automatically installed packages that are no longer needed. Check its proposed list, too.

Remove Java on Fedora, RHEL, or Arch

Package names and commands vary by distribution and release. On Fedora and many current RHEL-family systems, DNF manages packages. On Arch Linux, use Pacman.

  • Fedora or a DNF-based system: inspect packages with dnf list --installed '*java*' '*openjdk*', then remove the exact package with sudo dnf remove package-name.
  • Arch Linux: inspect with pacman -Q and remove the identified package with sudo pacman -R package-name. Review the dependency and removal information before confirming.

For example, Fedora package names may include a version and component, such as an OpenJDK headless runtime or development package. Do not assume that a package name from another distribution applies to yours. Use your package manager’s search and query commands, and remove only the packages you intend to uninstall.

When Java was installed manually

A Java installation extracted from an archive or installed by a vendor-provided script may not be registered with the system package manager. Common locations include /opt, /usr/local, and a user’s home directory, but the location depends on how it was installed. Check the resolved executable path and inspect shell configuration files for Java-related PATH or JAVA_HOME entries.

Before deleting files, identify the exact installation directory and confirm that no other application uses it. If you created a symbolic link or changed alternatives, remove or reset that configuration appropriately; do not delete an entire shared directory just because its name contains “java.” Also check for a vendor’s uninstall instructions. A manually installed runtime might be used by a service or application even if the system package manager reports no Java package.

Do not remove files under package-managed directories by hand as a substitute for the package manager. Doing so can leave the package database inconsistent and make future upgrades or removals harder.

Choose the right removal and verify it

Removing Java is not always the right fix. A Java-based server, build tool, desktop program, or business application may stop working without a runtime. If your goal is to remove an outdated release, consider installing a supported version first and configuring the system to use it, rather than removing every Java package.

After removal, check the result:

  1. Run java -version. If a different version appears, another installation is still available.
  2. Check command -v java to see where the remaining command is found.
  3. Query the package manager again to confirm which Java packages remain.
  4. If you changed PATH or JAVA_HOME, open a new terminal or reload the relevant shell configuration, then verify again.

The command may remain available because another Java version is selected through the system’s alternatives mechanism, because a manual installation is on your path, or because the shell has cached a command location. On Bash, hash -r clears the command-location cache. Alternatives tools, where present, can show or change the selected version; their exact commands differ by distribution.

Related

Frequently Asked Questions

Will uninstalling Java delete my files?
Package removal normally removes the installed software, not your personal documents. A package purge may delete package-managed configuration files. Manually installed files and application data may remain, so inspect their locations separately before deleting anything.

Can I uninstall one Java version and keep another?
Usually, yes. Remove the specific versioned package rather than a broad group of packages, and check the package manager’s removal plan. Then verify which version is active with java -version.

Does removing the JDK also remove Java?
It depends on the package relationships and how Java was installed. A JDK includes runtime components, but package managers may represent those components as dependencies or separate packages. Inspect the installed-package list and removal proposal rather than assuming one command removes everything.

Why does java -version still work after removal?
Another Java version may be installed, a manually installed executable may still be on your PATH, or an application may bundle a runtime. Use command -v java, resolve its path, and check the package database to find the source.

Is it safe to uninstall Java on Linux?
It is safe if no software you rely on needs it. Before confirming removal, review the dependent packages and consider whether servers, development tools, or desktop applications use Java. If uncertain, keep the runtime or test the affected applications after removal.

Uninstall Java on Linux: Commands for Each Distribution
Scroll to top