Ubuntu

How do I uninstall a package in Ubuntu?


While you work in the Linux environment, most applications or packages you found useful for solving your problems, but after trying these applications, you want to uninstall these packages from your system. It is an easier way to uninstall packages using the graphical interface. However, you should have basic knowledge about how to uninstall or remove a package from a Linux system using the command-line method.

In this tutorial, we will talk about how you uninstall a package in Ubuntu distribution using both methods: either using the GUI or by using the command-line environment.

Prerequisites

To uninstall or remove a package from the Ubuntu Linux system, you must have root privileges to run the terminal commands.

Methods to uninstall a package in Ubuntu 20.04 system

Using the following two ways, you can uninstall a package from the Ubuntu 20.04 operating system:

  1. Uninstall a package from Ubuntu using the Terminal (Command-line method)
  2. Uninstall a package from Ubuntu using the GUI

Method 1: Uninstall a package using the Terminal (Command-line method)

Most Ubuntu Linux users prefer to use the command-line method to uninstall or remove an application from the Ubuntu system. The command-line method offers more control and options for uninstalling the packages.

List installed Ubuntu packages

It is necessary to know the exact package name to uninstall a software or package from your Ubuntu system. Therefore, in Ubuntu 20.04 system, you can view the installed packages by using the following command:

$ sudo apt list --installed

The above command displays the large list of installed packages on your system. but, it would be difficult to find the exact package name from the displayed, installed packages list. To view output in the more readable form, use the ‘less’ with the above command as follows:

$ sudo apt list --installed | less

Press enter to move on to the next package.

You can also search the exact package name from the whole list by using the grep command as follows:

$ sudo apt list --installed | grep package_name

For example, to find all ‘apache2’ packages, use the below-mentioned command:

$ sudo apt list --installed | grep apache2

Commands to remove a package using Terminal in Ubuntu

The following four most commonly used commands that help you to remove a software package or an application from the Ubuntu system:

Uninstall a package using the ‘remove’ command
To uninstall or remove a package from the Ubuntu system, use the ‘apt-get remove’ command followed by the package name as follows:

$ sudo apt-get remove package_name

You can also remove more than one package at the same time by using the following command syntax:

$ sudo apt-get remove package_name1 package_name2

For example, we want to uninstall ‘zip’ and ‘wget’ packages from the Ubuntu system. Use the below-mentioned command to uninstall these packages:

$ sudo apt-get remove zip wget

Uninstall package using ‘purge’ command
The ‘apt-get remove’ command removes the entire package from your Ubuntu system. But, it leaves some packages and configuration files behind on your system. However, to completely uninstall a package including all configuration files, use the ‘purge’ instead of executing the ‘remove’ command. The following ‘purge’ command is used to uninstall a package from the Ubuntu system completely:

$ sudo apt-get remove ––purge package_name

For example, to uninstall apache2 packages along with all configuration files from your system, use the below command:

$ sudo apt-get remove ––purge apache2

Uninstall unused packages
When you install an application on Ubuntu, it may also download and install the dependencies required to install the application properly. When you uninstall the required packages, the packages dependencies still linger in your system but are unused. These leftover or unused packages can remove from the Ubuntu system by executing the following command:

$ sudo apt autoremove

You can also clean the outdated/ old packages from the cache by running the below-mentioned command:

$ sudo apt-get clean

Uninstall snap packages
The snap package manager is a part of the new Ubuntu versions. So, when you independently uninstall a package using snap, you need a list of all installed snap packages. Using the below-given command, you can easily display the list of all installed snap packages:

$ snap list

Once the installed snap packages list is obtained, use the following command to uninstall the snap package:

$ sudo snap remove package-name

For example, to uninstall the ‘discord’ application from the snap list, use the following command:

$ sudo snap remove discord

Method 2: Uninstall a package from Ubuntu using the GUI

The alternative way to uninstall a package is using the Ubuntu software center. The software package manager is available on the left sidebar of your Ubuntu desktop. To access this application click the ‘Ubuntu software’ icon or launch it using the application search bar as follows:

The following Ubuntu software manager window shows on your system. Click on the ‘Installed’ tab to see all installed packages. Here, you can search for an application that you want to uninstall from your Ubuntu system.

Select the application that you want to remove from your Ubuntu machine as follows:

Conclusion 

We learned different commands through which you can easily uninstall a package or software from your Ubuntu 20.04 system. Moreover, we also demonstrated how to remove or uninstall a package using the GUI of the Ubuntu software center. You can adopt any method from either uninstalling a package via command-line or using the GUI; these methods are useful for every Linux user.

About the author

Samreena Aslam

Samreena Aslam holds a master’s degree in Software Engineering. Currently, she's working as a Freelancer & Technical writer. She's a Linux enthusiast and has written various articles on Computer programming, different Linux flavors including Ubuntu, Debian, CentOS, and Mint.