Remove old Debian packages

As your Debian/Ubuntu system gets older, there might be a number of packages lying around on your hard disk, that you no longer need. These packages are called orphaned packages. Usually they contain libraries, that were required by another software package you installed. Maybe the software package was replaced by a new package, that dropped the dependency on that library (version). Or you removed the software package entirely, because you no longer needed it.

These orphaned packages are not used by any other packages and are therefore taking up useless space. You can remove them with deborphan.

If deborphan is not already installed on your system, install it.

  1. sudo apt-get install deborphan

Now you can use the following combination of commands to automatically remove all software packages, that are found by deborphan.

  1. sudo deborphan | xargs sudo apt-get remove --purge

The latter should be done regularly to keep the number of redundant packages at a minimum.

Shameless plug: If this post was useful to you, please consider buying yourself something from one of my Amazon stores: US store, UK store, FR store, DE store, CA store. If you're not into Amazon, why not donate something to GNOME, Mozilla or Wikipedia? Thank you!

2 Responses to “Remove old Debian packages”

  1. Timo says:

    I think
    sudo apt-get autoremove
    does the same and can be done with onboard tools in edgy. I did that some days ago and it freed 180MB of my hard disk.

  2. Patrick says:

    No. sudo apt-get autoremove is different. deborphan searches for packages that have no dependency at all. In Edgy apt keeps track of packages, that were installed as dependencies. If you use the option autoremove, apt will use this information collected earlier to remove all packages, that were installed as dependencies and that are no longer needed. Optionally it takes a parameter and removes only the packages, that were installed as dependencies of a particular program.

    See https://wiki.ubuntu.com/AptAutoRemove for a discussion of this feature.

    In fact, autoremove is much more powerful then deborphan. While the packages deborphan declares as unused are mostly libraries (it can’t know, if a tool was installed as a dependency, because it has no database), autoremove is likely to remove packages of programs, that were installed as dependencies of other program packages, too.

    To be fair, I wasn’t aware of autoremove since it was introduced in Edgy and does not seem to be available upstream (in Debian). Depending on your situation, autoremove might be better than deborphan or not.

Leave a Reply