Home Ubuntu How to Completely Uninstall Java on Ubuntu

How to Completely Uninstall Java on Ubuntu

Uninstalling Java from your Ubuntu system may seem like a simple task, but it involves more than just removing the package. To ensure the complete and thorough removal of Java, including any residual files and configurations, we will guide you through a comprehensive step-by-step process in this article.

Follow this guide to learn the process of completely uninstalling Java from the Ubuntu system.

How to Uninstall Java in Ubuntu

First, open the terminal on Ubuntu from the application menu and check the installed Java versions by typing the following command:

$ java --version
Check Java in Ubuntu
Check Java in Ubuntu

If you have multiple Java versions installed on your system, you have to execute the following command:

$ sudo update-alternatives --config java

To uninstall a specific Java version on the Ubuntu system, you can use the apt remove command followed by the Java package name with  * at the end.

The * character is a wildcard that matches any additional characters, so using it in the package name can help remove multiple packages that share a common prefix.

$ sudo apt remove <package_name>-* -y

Replace <package_name> with the name of the Java package, you want to remove. For example, if you want to remove OpenJDK 11 from the Ubuntu system, you can use the following command.

$ sudo apt remove openjdk-11-* -y
Remove Java in Ubuntu
Remove Java in Ubuntu
Note: For multiple Java versions, you have to remove each version separately.

Remove Unused Dependencies in Ubuntu

To remove any residual packages, dependencies, and cached package files related to Java, it is recommended to run the following command.

$ sudo apt autoremove -y && sudo apt clean -y
Remove Unused Dependencies in Ubuntu
Remove Unused Dependencies in Ubuntu

Once the cleanup is done, you can verify the Java uninstallation on Ubuntu using the following command:

$ java --version
Check Java Version in Ubuntu
Check Java Version in Ubuntu

This ensures that you have successfully uninstalled Java from your system.

Conclusion

Removing Java from Ubuntu is simple and can be done using the apt remove command followed by the package name with a wild card character.

The wildcard character removes the Java package that shares the common prefix. There might be some residual files and configurations left behind, so to remove them completely, the users must go with the additional steps mentioned ins this article. This will help ensure the complete uninstallation of Java on the Ubuntu system.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.