Home > English, Tech Crunch > HOWTO Clean packages on a Debian system

HOWTO Clean packages on a Debian system

This article was first written in July 2005 for the BeezNest technical
website (http://glasnost.beeznest.org/articles/282).

A Debian system can take more and more disk space as you install new packages. Let’s see how we can detect which packages are no longer used (unsused/obsolete/transitional) and clean them if we are sure we don’t need them anymore.

First, it is good to know that when you use apt (apt-get, aptitude, dselect, synaptic, …) the files downloaded are stored in /var/cache/apt/archives, and never cleaned. To clean them, use the following:

  • to clean obsolete packages (packages of version which would not be installed if requested now)
$ sudo apt-get autoclean
  • to empty all /var/cache/apt/archives/*.deb
$ sudo apt-get clean

If using aptitude, it keeps a track of packages taken to fulfill dependencies to other packages, so not installed explicitely, which allows to remove packages when the package that needed it is removed.If using another apt tool, it does not keep such information, so there are probably dependencies left after a removal.

To keep track anyway of these dependencies, Debian provides the debfoster tool.

To detect such orphaned packages, Debian provides the deborphan tool.

When used without parameters, it only lists the libraries on which no package depends.

$ deborphan

I suggest using the following parameters, which list all orphaned packages, with their respective sizes (works only starting from Sarge).

$ deborphan -az

And I personally sort them to first remove the biggest ones.

$ deborphan -az | sort -n

There are lots of locales supported by Debian packages, which may take up quite a lot of disk space. The Debian tool localepurge permits to wipe the unused locales.

When upgrading from one Debian release to another, some packages maybe left without being of any use, and are pretty difficult to track. To detect them, Debian provides the apt-show-versions tool.

There are also many transitional dummy packages that exist only for the upgrade to happen smoothly. To detect them:

$ dpkg -l|grep dummy
$ dpkg -l|grep transitional
$ dpkg -l|grep obsolete
  1. Steven P
    October 17, 2013 at 1:55 pm

    2013, 17 November

    For what it’s worth, Sun java appears removed from repositories configured for out of the box use:

    sudo apt-get install sun-java6-jdk tomcat6 maven2 postgresql
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package sun-java6-jdk is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘sun-java6-jdk’ has no installation candidate

    I’ve never had success installing Tomcat from repositories, and I will not build a custom deal and risk breaking the server.

    Java is really an unfriendly player.

    • October 17, 2013 at 11:37 pm

      Why don’t you just use OpenJDK if for Tomcat only?

  2. April 22, 2016 at 3:48 am

    thanks, simple. works for me.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: