While using Linux, we all run out of disk space some time or the other. One of the simple ways to free up disk space is to just remove unnecessary packages in Linux. Otherwise, over time, our system will get crowded with too many applications and packages which eat up a lot of space. Also, when we install a Linux package, it invariably installs several dependencies along with it. They continue to exist even after you have uninstalled the original application. In this article, we will learn different ways to find and remove unused packages in Linux.
Why Remove Unused Packages in Linux
It is important to regularly find and remove unnecessary packages from our Linux system. Otherwise, they will fill up our hard disk and we will run out of disk space. This will adversely affect our system performance and sometimes it may even crash. Sometimes, these applications are enabled to auto start in the background during system startup. In such cases, they will be automatically loaded into your system’s memory and you will run out of RAM too.
When you update or upgrade your system, all these unused packages will be updated unnecessarily, causing unnecessary downloads, increased data consumption and longer update time. Their dependencies might interfere with those of the applications that you actually use and disrupt your system. For all these reasons, it is prudent to periodically clean up your system of unused packages.
How to Find Unused Packages
Before we uninstall a package, we need to find out if it is present in our system or not, along with its exact name. For this purpose, you can use dpkg or apt commands. Here are the commands to list all installed packages on Debian/Ubuntu systems.
$ sudo apt list --installed
OR
$ sudo dpkg --list
If you want to search for a specific package name, you can run the following commands.
$ sudo apt list --installed | grep <software_name>
OR
$ sudo dpkg --list | grep <software_name>
For example, here are the commands to search for package name of firefox in your system.
$ sudo apt list --installed | grep firefox
OR
$ sudo dpkg --list | grep firefox
On Redhat/Fedora/CentOS systems, you can use Yum package manager.
# yum search <package_name>
OR
# yum list *<package_name>*
You can also find orphaned packages on your system using third-party packages such as deborphan for Debian/Ubuntu systems and rpmorphan for RPM-based Linux such as Redhat/Fedora/CentOS.
Here is the command to install deborphan and use it to list orphaned packages.
$ sudo apt-get install deborphan
$ deborphan
Here is the command to install rpmorphan and use it to list orphaned packages.
# dnf install perl perl-Tk
# rpm -Uvh rpmorphan-1.16-1.noarch.rpm
# rpmorphan
How To Remove Unused Packages in Linux
Once you have found out all unused packages on your system, you can use any of the following methods to uninstall them. First, we will cover different solutions for Debian/Ubuntu systems, followed by those for RPM-based systems.
1. Using apt-get purge
APT is one of the most popular package managers for Ubuntu systems. It provides apt-get command that is commonly used for installing as well uninstalling software. You can use ‘apt-get purge’ command followed by package name, to completely uninstall the package. Here is its syntax.
$ sudo apt-get purge <package_name>
The above command will also remove configuration files and user settings along with software files. It is useful if you are sure you will never use the package again, or if you want to do a fresh re-install.
2. Using apt-get remove
You can also use ‘apt-get remove’ command, followed by package name, to remove only the software files, but retain the configuration files and user settings.
$ sudo apt-get remove <package_name>
3. Using apt-get autoremove
When we install a package, it also installs several dependencies along with it. When we remove the package using above commands, its dependencies are not removed. To remove these dependencies, you can run the following command.
$ sudo apt-get autoremove
The above command will automatically scan your system for all unused dependencies and display them along with Y/N prompt to confirm their uninstallation. It is a good practice to regularly run this command to keep your system clean.
4. Using ppa-purge
The above commands work only on packages which have been installed using apt-get command. If you have installed the package via ppa repository, then you can use ppa-purge command to completely remove it from your system. Here is the command to install ppa-purge utility.
$ sudo apt-get install ppa-purge
Once you have installed ppa-purge, you can remove a package using the following command.
$ sudo ppa-purge <ppa:repository-name>
5. Using dpkg
If you have installed packages using dpkg package manager, then you can uninstall them using the following command.
$ sudo dpkg --remove <package_name>
6. Using Dnf
On RPM-based systems such as Redhat, Fedora and CentOS, you can use dnf command to easily remove packages using the following command.
$ sudo dnf --remove <package_name>
The above command will only remove the package and not its dependencies. In order to remove these dependencies, you need to also run the following command afterwards.
$ sudo dnf autoremove
8. Using Yum
Yum is a popular package manager for RPM-based systems such as Redhat, Fedora, and CentOS. You can remove RPM packages from your Linux system using the following command. Please remember to log in as root or privileged user before you run these commands because only they have adequate permission to run them.
$ yum remove <package_name>
OR
$ yum erase <package_name>
Once you have removed the above package, you
Conclusion
In this article, we have learnt several simple ways to quickly find and remove unused packages in Linux. You can use any of these methods depending on your requirements. It is important to regularly identify and uninstall unnecessary packages from your system, to avoid running out of disk space. This will keep your system nimble and healthy.
Also read:
How to Uninstall NVIDIA Drivers in Ubuntu
How to Clone Object in JavaScript
How to Split Python List into Even Chunks
Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI & software development.