Security

Remove Package in Ubuntu:How to Uninstall

Remove Package in Ubuntu :During software installation, package managers download and install the main binary package and all the necessary dependencies. Once the application is no longer needed, it is advisable to remove it since its packages take up storage space and may hinder performance.

This guide teaches you how to uninstall or remove packages in Ubuntu using the command line

Prerequisites

  • Ubuntu installed (this tutorial uses Ubuntu 22.04).
  • Command-line access.
  • A user account with sudo privileges.

Remove Package in Ubuntu via CLI

The default Ubuntu command-line application management tools are APT, DPKG, and Snap. Each utility provides methods for uninstalling and removing software from the system.

Read the sections below for instructions on uninstalling packages using the Ubuntu CLI.

Option 1: Uninstall Ubuntu Packages with APT

The APT package manager offers several ways to remove unwanted packages. The most common way to uninstall an app with APT is to use the apt remove command:

To remove a package but keep its configuration files, use the following command:

sudo apt remove <package_name>

Completely Uninstalling a Package

To remove a package along with its configuration files, use the following command:

sudo apt purge <package_name>

Removing Unused Dependencies

After uninstalling a package, you might want to remove packages that were installed as dependencies but are no longer needed. Use the following command:

sudo apt autoremove

Cleaning Up

To clean up the local repository of retrieved package files, you can use:

sudo apt clean

Example

If you want to completely remove the package example-package, you would run:

sudo apt purge example-package
sudo apt autoremove
These commands will ensure that example-package and its associated dependencies that are no longer required are removed from your system.

Checking Installed Packages

To see a list of all installed packages on your system, you can use:

dpkg --list

If you want to filter the list by a specific package name, you can use grep:

dpkg --list | grep <package_name>

Verifying Package Removal

To verify that a package has been successfully removed, you can use:

dpkg --list | grep <package_name>

If the package does not appear in the list, it has been removed.

Removing PPAs (Personal Package Archives)

If you have installed packages from a PPA and want to remove the PPA, you can use the add-apt-repository command. First, list the PPAs:

ls /etc/apt/sources.list.d/

Then, remove the desired PPA:

sudo add-apt-repository --remove ppa:<ppa_name>

After removing the PPA, update your package list:

sudo apt update
Advanced Package Management

a. Using aptitude

aptitude is an alternative to apt that provides more options and a text-based interface. To install aptitude:

sudo apt install aptitude

You can then use aptitude to remove packages:

sudo aptitude remove <package_name>
sudo aptitude purge <package_name>

Removing Specific Versions

If you need to remove a specific version of a package, use:

sudo apt remove <package_name>=<version>

Conclusion

After reading this article, you should be ready to uninstall or remove packages in Ubuntu. The guide provided detailed instructions for package removal using both the command line and the GUI.

Next, learn how to list all installed packages in Ubuntu.