Uninstalling Packages With Apt Package Manager

Uninstalling Packages With Apt Package Manager

If you’re running a Debian or Ubuntu-based distribution and want to get rid of a package, you can do so in several methods. However, knowing when to use each technique and what sets them apart can be difficult. Using the apt package manager, we will explore the different options for finding and removing packages. We’ll break down when you should use the “purge” instruction versus the “remove” one. More than that, we will provide you with some helpful instructions to run after an uninstall to ensure a clutter-free operating environment. When you’re done reading this article, you’ll have a firm grasp on how to uninstall software packages quickly and easily.

Find The Package You Want To Uninstall

First things first, we need to find the package which we want to uninstall. We can very easily locate our package’s exact name with the following :

$ dpkg --list | grep <package-name>

This helps us to locate the exact package which we would require for the future steps. Once, we have located out desired package, we can move onto the next step.

Obtaining a list of installed packages

1. Using dpkg

Obtaining a list of installed packages in Linux is beneficial for a variety of purposes, including tracking installed software and creating a backup of the system. Thankfully, there are several methods to complete this task.

The dpkg command, which is a package manager for Debian-based systems, is a common method. By executing the following command in the terminal, a catalog of all installed packages can be obtained:

dpkg --list

This command outputs an extensive list of all installed packages, including the package name, version, and a brief description of each package.

2. Using apt

Using the apt command, which is a package manager constructed on top of dpkg, is another useful method. Using apt, we can obtain a list of all installed applications by entering the following command in the terminal:

apt list --installed

This command provides a complete detail of installed packages, including the package name and version number.

If you are still confused on which package manager to use here’s an amazing article that compares apt vs dpkg.

Uninstalling Packages With Apt

When talking about uninstalling packages using apt package manager, we have the following two options :

  • remove
  • purge

1. Using apt remove

To remove a package using ‘remove‘ simply type :

$ sudo apt remove <package-name>

2. Using apt purge

We can very easily remove packages with the ‘purge’ command as such :

$ sudo apt purge <package-name>

What’s the difference between ‘remove‘ and ‘purge‘ ?

So the begging question here is ‘remove‘ and ‘purge‘ and when to use what ?

The primary difference being ‘remove‘ and ‘purge‘ is that ‘remove‘ only gets rid of the package leaving any configuration files untouched. Whereas ‘purge‘ not only removes the package but also removes all configuration files OUTSIDE THE HOME DIRECTORY.

A Fun Little Secret

Quite contrary to what their primary function is, both ‘purge‘ and ‘remove‘ can be used to INSTALL packages. This can be achieved by appending a ‘+‘ at the end of the package name as such :

$ sudo apt <remove/purge> <package-name>+

Post Uninstall Clean Up

At this point, we have successfully removed/purged our package. Now, we can run some commands to perform post-removal clean up out of good practice

We can clear the cache of the old/outdated packages with :

$ sudo apt clean

We can remove unrequired packages with :

$ sudo apt autoremove

Finally, any failed/broken installs can be fixed with :

$ sudo apt -f install

Conclusion

Finally, with the apt package manager, removing software from a Linux machine is a breeze. To begin, we can use the dpkg command to find the package we wish to remove. The apt program can then be used to uninstall or clean the package. The main distinction between the two is that remove does not delete setup files, whereas purge does. Furthermore, by adding a + to the package name, either command can be used to install it. Finally, it’s recommended that you clear the cache, remove any unused packages, and repair any broken installs using apt after uninstalling packages.

References

If you want to learn more on apt, here’s Ubuntu’s official documentation to get you going.