This brief tutorial will explain how to find and remove unused packages in CentOS and Ubuntu Linux distributions using Deborphan, Gtkorphan, and Rpmorphan utilities.
Table of Contents
Introduction
Running out of low disk space? You may need to check for unused packages (orphaned packages) in your hard drive. The orphaned packages are nothing but the packages which will be installed as dependencies/libraries when you install a software in your Linux system.
As you may know already, whenever we install an application, some other packages (dependencies) will also be installed along with the application you are installing. These dependencies might exist in your hard drive even after you removed the application.
After a particular period of time, your hard drive will be flooded with unused or orphaned packages, and you might end up with low disk space.
Low disk space not only affects the system performance, it will also not let you to install new applications due to insufficient space. So, it is very recommended to wipe out the orphaned packages at regular interval.
First, we will see how to find and remove unused packages in Ubuntu and its derivatives such as Linux Mint, elementary OS.
Find and remove unused packages in Ubuntu using Deborphan
Deborphan is a command-line utility that can be used to find and remove unused or orphaned packages in DEB based systems. It is available in the official repositories. To install it, open up the Terminal and run the following command:
$ sudo apt-get install deborphan
Once installed, run it as shown below to find out the orphaned packages.
$ deborphan
This will list all the unused packages.
openoffice.org-hyphenation rhythmbox-plugin-magnatune myspell-en-gb libgnutls-openssl27 myspell-en-za libusb-0.1-4 libreadline6
As you see above, I have few unused packages in my Ubuntu system.
To remove the orphaned packages, run:
$ sudo orphaner
Select the files and select Ok to remove the all fines.
Suggested read:
Find and remove unused packages in Ubuntu using Gtkorphan
Gtkorphan is a graphical tool that allows us to find and remove orphaned packages. Gtkorphan is only for desktop editions. If you're using Ubuntu server without GUI, use Deborphan instead.
Gtkorphan is available in the default repositories. To install it, run:
$ sudo apt-get install gtkorphan
Once installed, launch it by running the following command from the Terminal:
$ sudo gtkorphan
Gtkorphan's default interface will look like below.
Since we already removed the orphaned packages, it shows nothing. However, at the first time, we need to initialize the system in order to keep track of needed packages, even if they are listed as orphaned.
To do so, from the main window, expand the“Options” section and check the box that says - “Show all orphan packages, not only those in the libs section”.
Now, Gtkorphan will list the orphaned packages. However, you must careful here. As you see in the above picture, Gtkorphan lists some important packages as unused. We shouldn't remove them. In order to keep the important packages, right click on the package name, and click Hibernate package option.
This will keep the packages from removal by Gtkorphan. You only need to do this at the first time. After that, you can remove the orphaned packages if any exists.
Once you hibernated all important packages, scroll down through the list of other packages. If you don't need any package, just right click on it and click "Select for removal" option.
Alternatively, run the following command to remove the unused/orphaned packages all at once.
$ sudo apt-get autoclean && sudo apt-get autoremove
Congratulations! Now, you have freed up some space in your hard drive.
Find and remove unused packages in CentOS using Rpmorphan
Rpmorphan is a command line utility that can be used to find orphaned packages in RPM based systems, such a RHEL, CentOS, Fedora, AlmaLinux, Rocky Linux, and SUSE etc.
Rpmorphan consists of the following useful tools:
- rpmusage : display rpm packages last use date.
- rpmdep : display the full dependency of an installed rpm package.
- rpmduplicates : find programs with several version installed.
- rpmextra : find installed packages not in distribution.
Before installing Rpmorphan, make sure you have installed Perl and perl-Tk packages. To install these packages, run the following command as root user:
# dnf install perl perl-Tk
On older RHEL versions, use yum instead of dnf.
Then, download Rpmorphan package from the following link. As of writing this, the latest version was 1.16.
Once downloaded, install rpmorphan using command:
# rpm -Uvh rpmorphan-1.16-1.noarch.rpm
After installing rpmorphan, run it to find the orphaned libraries:
# rpmorphan
Sample output:
libsysfs
It's also possible to display the orphaned packages of a specific period.
For example, to display all orphaned packages that are installed in the last 2 days, run:
# rpmorphan --all -install-time -2
Sample Output:
rpmorphan wget
Display all orphaned packages, installed 10 days ago (or more):
# rpmorphan --all -install-time +5
Sample output:
NetworkManager-adsl NetworkManager-bluetooth NetworkManager-glib NetworkManager-team NetworkManager-tui NetworkManager-wifi aic94xx-firmware audit authconfig avahi biosdevname btrfs-progs dnf-plugins-core dracut-config-rescue e2fsprogs epel-release firewalld gpg-pubkey grub2 iprutils irqbalance ivtv-firmware iwl100-firmware iwl1000-firmware iwl105-firmware iwl135-firmware iwl2000-firmware iwl2030-firmware iwl3160-firmware iwl3945-firmware iwl4965-firmware iwl5000-firmware iwl5150-firmware iwl6000-firmware iwl6000g2a-firmware iwl6000g2b-firmware iwl6050-firmware iwl7260-firmware kbd kernel kernel-tools kexec-tools libsysfs lvm2 man-db microcode_ctl openssh-clients openssh-server parted passwd postfix python-setuptools rootfiles rsyslog selinux-policy-targeted sudo tar tuned xfsprogs
Display all unused packages since 10 days or more:
# rpmorphan --all --access-time 10
Sample output:
NetworkManager-glib NetworkManager-tui aic94xx-firmware btrfs-progs dracut-config-rescue e2fsprogs gpg-pubkey grub2 ivtv-firmware iwl100-firmware iwl1000-firmware iwl105-firmware iwl135-firmware iwl2000-firmware iwl2030-firmware iwl3160-firmware iwl3945-firmware iwl4965-firmware iwl5000-firmware iwl5150-firmware iwl6000-firmware iwl6000g2a-firmware iwl6000g2b-firmware iwl6050-firmware iwl7260-firmware libsysfs man-db microcode_ctl openssh-clients parted passwd python-setuptools sudo tar
For more examples, refer the man pages.
# man rpmorphan
If you no longer need those orphaned packages, just remove them using yum command and free up your hard drive.
Related read:
- Remove Unnecessary Configuration Files On Debian-based Systems
- Debfoster - Keep Only Essential Packages In Debian And Ubuntu
Resources:
4 comments
I will use Gtkorphan,
“Gtkorphan lists some important packages as unused”, so how can I know if this package is belongs to an installed app -or it’s a dependencies for another package so I shouldn’t remove- I have a huge apps and haven’t time to search for each package is belongs or not 😕
Hi!
Or use a distro without this kind of the so called dependency hell. I use Slackware and have full control over every package that gets installed. Remember that every package could be a security risk. Cheers!
“With the current state of deborphan, frontends will do more harm
than good. At this time you really have to understand the inner
details of Debian packages, their relationships and also deborphan
itself. Everything around deborphan has evolved a lot, but deborphan
did not catch up, and is now a really low-level tool.
Frontends that make deborphan look like an easy to use and safe tool
are tricking their users.
I would advise possible front-end authors to implement their own
safe policies around package removal suggestions, and not use
deborphan as a data source.”
https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1818818.html
http://changelogs.ubuntu.com/changelogs/pool/universe/d/deborphan/deborphan_1.7.35/changelog
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=972509
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=981607
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=414865
Thanks for the heads up. Much appreciated.