How to Remove Orphaned Packages on Ubuntu

On Linux systems, the installation of some packages depends on others packages or libraries in order to work properly. For example, if you want to install a package named "mypackage", you need to its depended libraries.
Later if you uninstall "mypackage", the package containing the libraries would be still in the system with no use. To remove these packages we need to use some tools. In this tutorial, you will learn how to install some tools that are used to find and remove orphaned libraries from your Ubuntu 16.04 system. 

Normally, apt can manage dependencies between packages and apt-get autoremove offers you the possibility to remove any orphaned packages. But if you have installed depended package manually before installing "mypackage" would still stay in the system. So we need to use tools for this purpose.

Refer also : How to Install Specific Version of Package using apt-get

1) Gtkorphan

GtkOrphan is the graphical tool that allows you to find and remove orphaned packages. It implements a GUI front-end for deborphan, adding the package-removal capability which scans your system for orphaned libraries and removes them when you tell it to do so.

# apt install gtkorphan
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
 deborphan dialog libgtk2-gladexml-perl menu
Suggested packages:
 menu-l10n
The following NEW packages will be installed:
 deborphan dialog gtkorphan libgtk2-gladexml-perl menu

Now simply search the application from the launcher

Launch now the application. You can see a list of the orphaned packages presents in your system. You can pick those you want to remove. Now expand the "Options" with the right click and choose "Select for the removal".

2) Deborphan

DebOrphan is the command line tool that allows you to know the orphaned packages presents in your Linux system. Normally when you install gtkorphan, it comes with deborphan. But you only want to install deborphan, do as below:

# apt install deborphan

Now to list the orphaned packages, just use the command on the terminal

# deborphan 
libllvm3.8:amd64
libmircommon5:amd64
libsensors-applet-plugin0:amd64
libqmi-glib1:amd64

You can see that we have the same list as with gtkorphan. To remove all the orphaned packages, use the command:

# apt-get remove --purge `deborphan` 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following packages will be REMOVED:
 libllvm3.8* libmircommon5* libqmi-glib1* libsensors-applet-plugin0*
0 upgraded, 0 newly installed, 4 to remove and 23 not upgraded.
After this operation, 43.8 MB disk space will be freed.
Do you want to continue? [Y/n]

You can see that it proposes to remove all the 4 orphaned packages. Now if you want to exclude some specific packages, you can use the --exclude parameter as below

# apt-get remove --purge `deborphan --exclude=libsensors-applet-plugin0:amd64` 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  libllvm3.8* libmircommon5* libqmi-glib1*
0 upgraded, 0 newly installed, 3 to remove and 23 not upgraded.
After this operation, 43.8 MB disk space will be freed.
Do you want to continue? [Y/n]

Now you can see that it only proposes to remove 3 orphaned packages not 4 as before.

Now you know the two essentials tools which can help you to remove orphaned packages. However, you should notice that some dependencies are not correctly defined at the package level itself and deborphan can remove a component that may be useful for you, so be careful about it.

Alain Francois 12:05 am

About Alain Francois

IT Linux administrator passionate of free and open source software, I work on Linux Systems since some years on installations and deployments of certain solutions. I like to share my experiences with a wider audience by training and conferences.

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.