remove unused packages in linux

How to Remove Unused Packages in Linux

When we install a package or software in Linux it also installs tons of its dependencies. When we uninstall/remove this software from our Linux system, these packages are always left behind. Over time, our system becomes cluttered with such orphaned packages and they take up a lot of disk space. So it is advisable to remove unused packages in Linux at regular intervals. There are many third-party utilities that allow you to automatically find and delete such unused packages. In this article, we will look at several ways to remove unused packages in Linux. You can use these steps to delete unwanted packages from Ubuntu/Debian as well as RHEL/Fedora/CentOS systems.


How to Remove Unused Packages in Linux

Here are the different tools to remove unused packages in Linux.


1. Using Deborphan

Deborphan is a command utility that allows you to find unused packages in Ubuntu/Debian systems. Here is the command to install it.

$ sudo apt-get install deborphan

After it is installed, run it with the following command.

$ deborphan

It will list all unused packages

openoffice.org-hyphenation
myspell-en-gb
rhythmbox-plugin-magnatune
libgnutls-openssl27

You can remove these packages with the following command.

$ sudo orphaner

If will open a window and list all unused packages, that you can select, and hit the OK button for deletion.


2. Using Gtkorphan

Gtkorphan is a graphical tool that allows you to select and remove unused packages from Linux. It requires a Linux system with desktop environment, and it is not a command line utility. If your Linux does not have desktop, use Deborphan instead.

Here is the command to install Gtkorphan.

$ sudo apt-get install gtkorphan

Once it is installed, run the following command to start Gtkorphan.

$ sudo gtkorphan

It will show the following kind of window listing orphan packages in libs section. If you want to see orphan packages across all folders, just check the box labeled ‘Show all orphan packages..’.

Go through the list carefully. If you want to retain a package, then right click on its name, and select ‘Hibernate Package’ option. On the other hand, if you want to remove a package, right click on its name and select ‘Select for removal’.

Once you have gone through the list, click Ok to remove unused packages.


3. Using autoclean & autoremove

You can also run the following command to remove all unused packages at once.

$ sudo apt-get autoclean && sudo apt-get autoremove

However, it will not ask for any confirmation or list any package name. It will simply automatically find and remove unused packages in Linux.


4. Using Rpmorphan

Rpmorphan is similar to Deborphan, it is a command line utility to find and remove unused packages in RHEL/Fedora/CentOS Linux.

Here is the command to install it. First we need to install perl and perl-tk packages.

# yum install perl perl-Tk

Then download its RPM package from this link. For our example, we have downloaded version 1.16. Run the following command to install it.

# rpm -Uvh rpmorphan-1.16-1.noarch.rpm

Once it is installed run the following command to list unused packages.

# rpmorphan

Like deborphan, it will list all unused packages. If you want to display orphaned packages that were installed a couple of days back, use the install-time argument as shown below.

# rpmorphan --all -install-time -2

Similarly, if you want to list all unused packages that have not been accessed in last 2 days, use access-time argument.

# rpmorphan --all --access-time 2

Once you have the list of packages, you can use rm command to remove them.

That’s it. In this article, we have learnt 4 different ways to find and remove unused packages in Linux. Depending on your Linux distribution, you can use any of the above tools.

Also read:

How to Configure Master-Slave DNS Server in Linux
How to Restrict SFTP Users in Linux
How to Create Password Protected ZIP File in Linux
How to Determine File System Type in Linux
How to Password Protect File in Linux

Leave a Reply

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