Categories: Ubuntu

How to uninstall Java from Ubuntu

Why do we need Java on our computers? There are tons of applications developed using the java environment, so we need to install java on our computers to make the java-based application run with no difficulty.

In many cases, you may need to remove java from your computer, such as installing the latest version of java or freeing up space from your machine. Installing Java on Ubuntu is pretty straightforward, but uninstalling it is a hard nut to crack for many folks. In this guide, we will learn how many versions of java are there, what distinguishes them, and how to erase them from your computer completely.

How
Sponsored
to check the type of Java on Linux (Ubuntu):

Before erasing java from your device, the first check is to identify what type of java you have on your PC. If you have installed java just to run the java applications, it would most probably “Java Runtime Environment (JRE).” Or, if you have installed java for development purpose, then you may have one of the following:

  • Open JDK
  • Oracle Java

The difference between “Open JDK” and “Oracle Java” is that the former is open-source, whereas the latter is license-based. Oracle Java is much better when it comes to performance and stability.

How to identify the Java version on Linux (Ubuntu):

Before uninstalling java from your PC, it is essential to know which version of java you have got. To check it launch terminal by pressing “ctrl+alt+t” and type the below-mentioned command:

$java -version

The above command will also indicate whether the version of java is “Open JDK” or “Oracle JDK.”

Standard output if the version is “OpenJDK”:

Standard output if the version is “Oracle Java”:

If you don’t have any version of java on your machine, the standard output will display it and provide some commands to install it.

How to switch versions of Java on Linux (Ubuntu):

Interestingly, you can have more than one versions of java on your device, and you can check and switch any of them by using the command mentioned below:

$sudo update-alternatives –config java

The above command is displaying the different versions of java I have on my PC. To switch, simply type the number and press “Enter.”

How to check the installation method of Java on Linux (Ubuntu):

In some cases, it is crucial to identify the method of installation of java. To check it, use the command:

$dpkg -l | grep openjdk

Sponsored

For oracle java use:

$dpkg -l | grep oracle-java

The above output will indicate whether the package is installed from an official repository or a third-party repository. The above screenshots are demonstrating that “Oracle Java” is installed using the third-party repository “Linux pricing,” whereas “OpenJDK” is installed using the official Ubuntu repository.

How to uninstall Java from Linux (Ubuntu):

In the above discussion, we learned that there are multiple versions of java; you can have all of them on your PC at a time and conveniently switch them. Various approaches can be used to delete java from ubuntu. To completely erase “OpenJDK,” use:

$sudo apt purge openjdk-11*

Or

$sudo apt remove –autoremove openjdk-11*

And to remove oracle java use:

$sudo apt purge oracle-java16-*

Or

$sudo apt remove –autoremove oracle-java16-*

That’s it. Now you can verify it using the command:

$java -version

Conclusion:

Java is one of your PC needs since many applications are developed and published using a java environment. Installing java on ubuntu is a simple procedure, but it is no less than a hassle for many uninstalling since there are multiple versions of java. In this guide, we learned how to identify which version you have on your PC and completely uninstall it.

The rise of Python and security issues has hit the popularity of Java. However still, java is the third most popular language among developers, but for how long nobody knows, the concerns related to its security are still there.

Ubuntu Server Admin

Recent Posts

Install FreePBX and Asterisk on Ubuntu 24.04 LTS for security patches until 2036

Deploying FreePBX and Asterisk on a single Ubuntu virtual machine in a public cloud is…

11 hours ago

Certification as a strategy: How Ubuntu & SystemReady boost hardware competitiveness

Canonical and MediaTek enhance reliability, accelerate market entry and reduce Total Cost of Ownership (TCO)…

11 hours ago

Ubuntu 20.04 LTS on Azure: how to stay secure after standard support ends

As Ubuntu 20.04 LTS (Focal Fossa) standard support ends on May 31, 2025, Azure users…

11 hours ago

Ubuntu Weekly Newsletter Issue 881

Welcome to the Ubuntu Weekly Newsletter, Issue 881 for the week of February 23 –…

1 day ago

Experiment Tracking with MLFlow in Canonical’s Data Science Stack

Welcome back, data scientists! In my previous post, we explored how easy it is to…

1 day ago

How to Install vLLM on Linux Using 4 Easy Steps

In this article, we will see how to install vLLM on Linux using 4 easy…

2 days ago