How To Uninstall Java On Linux – Removing Java Runtime From Linux

If you need to know how to uninstall java on linux, the process is straightforward. You remove the relevant package and clear environment variables. This guide walks you through every step, whether you use Ubuntu, Fedora, or another distribution.

Java can be installed in multiple ways on Linux. The uninstall method depends on how you installed it. We cover package managers, manual installations, and environment cleanup.

Why Uninstall Java On Linux?

You might need to remove Java for security updates, version conflicts, or freeing up space. Old Java versions have known vulnerabilities. Removing them keeps your system safe.

Another reason is switching to a different Java runtime. Maybe you want OpenJDK instead of Oracle Java. Or you need a specific version for a project.

How To Uninstall Java On Linux

This section covers the main methods. Choose the one that matches your installation type.

Check Current Java Installation

First, verify what Java is installed. Open a terminal and run:

java -version

This shows the version and vendor. Also check the Java compiler:

javac -version

List all installed Java packages with your package manager. For Debian-based systems:

dpkg -l | grep java

For Red Hat-based systems:

rpm -qa | grep java

This gives you a clear picture of what needs removal.

Uninstall Java On Ubuntu Or Debian

Ubuntu and Debian use APT. Remove Java packages with apt-get or apt.

Remove OpenJDK

OpenJDK is common. Remove it with:

sudo apt-get remove openjdk-*

Or use apt:

sudo apt remove openjdk-*

This removes all OpenJDK versions. Confirm when prompted.

Remove Oracle Java

If you installed Oracle Java via PPA, remove the package:

sudo apt-get remove oracle-java*

Then remove the PPA:

sudo add-apt-repository --remove ppa:linuxuprising/java

Update package lists:

sudo apt update

Purge Configuration Files

To remove configuration files too, use purge:

sudo apt-get purge openjdk-*

This ensures no leftover files remain.

Uninstall Java On Fedora Or CentOS

Fedora and CentOS use DNF or YUM. Remove Java packages accordingly.

Remove OpenJDK

For DNF (Fedora):

sudo dnf remove java-*

For YUM (older CentOS):

sudo yum remove java-*

This removes all Java packages. Check with rpm if any remain.

Remove Oracle Java

If you installed Oracle Java manually, find the RPM package name:

rpm -qa | grep jdk

Then remove it:

sudo rpm -e jdk-11.0.12

Replace with your actual package name.

Uninstall Java On Arch Linux

Arch uses Pacman. Remove Java with:

sudo pacman -R jre-openjdk

Or remove all Java packages:

sudo pacman -R $(pacman -Q | grep java | awk '{print $1}')

This removes all Java-related packages in one command.

Uninstall Manually Installed Java

If you installed Java from a tarball, delete the directory and update environment variables.

Find The Installation Directory

Check where Java is installed:

which java

This shows the symlink location. Use readlink to find the real path:

readlink -f $(which java)

Common directories are /usr/local/java, /opt/java, or /usr/lib/jvm.

Delete The Directory

Remove the entire Java directory:

sudo rm -rf /usr/local/java/jdk-11.0.12

Adjust the path to match your installation.

Remove Symlinks

Remove symlinks in /usr/bin:

sudo rm /usr/bin/java /usr/bin/javac /usr/bin/jar

Check for other symlinks:

ls -la /usr/bin | grep java

Remove any that remain.

Clear Environment Variables

After removing Java packages, clear environment variables. This prevents errors from old settings.

Check Current Variables

View JAVA_HOME and PATH:

echo $JAVA_HOME
echo $PATH

Look for any Java references.

Edit Shell Configuration Files

Environment variables are set in files like .bashrc, .bash_profile, .zshrc, or .profile. Edit the relevant file:

nano ~/.bashrc

Find lines containing JAVA_HOME or PATH modifications with Java. Remove or comment them out.

Common lines to remove:

export JAVA_HOME=/usr/local/java/jdk-11.0.12
export PATH=$PATH:$JAVA_HOME/bin

Save the file and reload:

source ~/.bashrc

Check System-Wide Variables

Some distributions set Java in /etc/environment or /etc/profile. Check these files:

cat /etc/environment
cat /etc/profile

Remove any Java references. Edit with sudo:

sudo nano /etc/environment

Update Alternatives System

Linux uses update-alternatives to manage multiple Java versions. Remove Java from alternatives:

sudo update-alternatives --remove java /usr/lib/jvm/java-11-openjdk-amd64/bin/java

Replace the path with your actual Java location. Check current alternatives:

sudo update-alternatives --config java

If no alternatives remain, the command shows an error.

Verify Java Removal

After uninstalling, confirm Java is gone.

Check Java Command

Run:

java -version

You should see “command not found” or a similar error.

Check For Leftover Files

Search for any Java files:

find / -name "java" -type f 2>/dev/null

This finds any remaining Java binaries. Remove them if found.

Check Environment Variables

Verify JAVA_HOME is no longer set:

echo $JAVA_HOME

It should return an empty line.

Common Issues And Fixes

Sometimes Java removal leaves traces. Here are common problems and solutions.

Java Command Still Works

If java -version still shows a version, a different installation exists. Check all installed packages again. Use dpkg or rpm to find hidden packages.

Also check /usr/local and /opt directories for manual installations.

Environment Variables Persist

If JAVA_HOME still shows after removal, you missed a configuration file. Check all shell startup files. Also check /etc/profile.d/ for Java scripts.

Permission Denied Errors

When removing system files, use sudo. If you get permission errors, you might be in the wrong directory or the file is protected.

Frequently Asked Questions

How Do I Uninstall Java On Linux Completely?

Remove all Java packages with your package manager, delete manual installations, and clear environment variables from shell config files. Verify with java -version.

What Is The Command To Remove Java From Ubuntu?

Use sudo apt-get remove openjdk-* for OpenJDK. For Oracle Java, use sudo apt-get remove oracle-java*. Then purge with sudo apt-get purge openjdk-*.

How To Uninstall Java 11 On Linux?

Find the package name with dpkg -l | grep java or rpm -qa | grep java. Remove it with apt-get remove or dnf remove. Delete the installation directory if manually installed.

Do I Need To Restart After Uninstalling Java?

No restart is required. However, you should log out and log back in for environment variable changes to take effect. Or source your shell config file.

Can I Have Multiple Java Versions Installed?

Yes, you can. Use update-alternatives to switch between them. Uninstalling one version does not affect others unless you remove all packages.

Final Tips For Clean Removal

Always check for multiple installations. Java can be installed via package manager, manual tarball, or SDKMAN. Each requires different removal steps.

Backup your shell config files before editing. This lets you restore if something goes wrong.

After removal, consider installing a fresh version if needed. Use your package manager for simplicity.

Remember to check for Java in /opt, /usr/local, and /usr/lib/jvm. These are common locations for manual installs.

If you use SDKMAN, remove Java with sdk uninstall java 11.0.12. Then remove SDKMAN itself if not needed.

Cleaning up environment variables is crucial. Even if Java binaries are gone, old paths can cause confusion for other tools.

Test your removal by running a Java-dependent application. If it works without Java, you have a different runtime installed.

For servers, ensure no critical applications rely on Java before removal. Check running processes with ps aux | grep java.

Document your steps for future reference. This helps if you need to reinstall or troubleshoot later.

Uninstalling Java on Linux is simple once you know the method. Follow the steps for your distribution and installation type. Clear environment variables for a complete removal.

With these instructions, you can confidently remove Java from any Linux system. Your system will be cleaner and more secure.