we are going to learn the steps for uninstalling packages with apt from our Debian/Ubuntu systems.

Find The Package we 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.

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
$ sudo apt remove <package-name>
2. Using apt purge
$ 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.

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
PS: (Trick)

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 <package-name>+
//Or
$ sudo apt purge <package-name>+

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *