In this article, we cover how to remove a package in Ubuntu. There are times when a certain package are no longer needed. It have served the purpose for us. And, wise thing would be to remove such packages. Such packages not only take up disk space but also require internet data whenever we update our system. In addition to, they may slow our machine in case we don’t have the latest hardware.
There are two method we cover here to remove a package in Ubuntu –
- apt and
- dpkg.
A package not always works in isolation. It requires certain other packages for it to work. We call these other packages – dependencies. So, when we remove a package then its most obvious that we don’t require its associated dependencies as well. But, condition is those dependencies shouldn’t be required by any other package installed in our system. Otherwise, we can’t remove such dependencies.
So, we cover both the parts here – removing a package as well as its dependencies.
Note: Following operations would require you to have superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.
Remove a package in Ubuntu
Method I. Removing packages through apt. If we want to just remove the package, and want to retain its configuration files, system directories etc. –
sudo apt remove [package-name]
If we want to remove both the packages and its dependencies but want to retain their configuration files, system directories etc. –
sudo apt remove --auto-remove [package-name]
here, –auto-remove removes dependencies.
On the other hand, if we want to remove a package and its dependencies completely including its configuration files, system directories etc. –
sudo apt purge --auto-remove [package-name]
But, what if we want to remove config files, system directories etc. for a package but not for its dependencies –
sudo apt purge [package-name] sudo apt autoremove
If we chose not to remove package dependencies now and would like to remove the dependencies along-with their configuration files and system directories –
sudo apt purge --auto-remove
Method II. Alternately, we can use dpkg to remove a package –
dpkg -r [package-name]
To purge a package –
dpkg -P [package-name]
We prefer to remove dependencies with apt without removing its configuration files, system directories etc. –
sudo apt autoremove
To purge (i.e. including configuration files, system directories etc.) associated dependencies –
sudo apt purge --auto-remove
In conclusion, we have covered how to remove a package in Ubuntu here.