In this module, we are going to learn the steps for uninstalling packages with apt from our Debian/Ubuntu systems.
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.
Uninstalling Packages With Apt
When talking about uninstalling packages using apt package manager, we have the following two options :
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
Thus we learnt how we can easily remove packages from Debian/Ubuntu based system using the apt package manager.