This site is now 100% read-only, and retired.

Removing unnecessary packages with deborphan

Posted by Steve on Thu 5 May 2005 at 17:42

Over time most Debian installations acquire packages which are no longer required - they've just been pulled in to satisfy dependencies of software you've since removed. Whilst there are many ways to fix this, the deborphan package is probably the simplest.

deborphan looks for orphaned packages, that is packages which are not required by any other package upon your system.

For example, if you install the game late as follows you'll see that you've pulled in a new package late-data:

root@lappy:~# apt-get install late
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  late-data 
The following NEW packages will be installed:
  late late-data

If you later decide to remove the late package you could do that easily :

dpkg --purge late

But you've left the late-data package upon your system, redundent and orphaned. You could manually remove this, but what about other similar packages you might have lying around, getting needlessly upgraded and wasting disk space?

Enter deborphan. Install it:

root@lappy:~# apt-get install deborphan

Once installed simply run it to display a list of the packages it thinks you don't need upon your system:

skx@lappy:~$ deborphan 
libsdl-image1.2

(Note that you don't need root privileges to use this tool, it merely reads the installed package lists - it won't remove any packages itself, merely tell you what it thinks you should remove).

As we can see it's decided that the libsdl-image1.2 package isn't required, because no currently installed package depends upon its presence.

There are some other options you can give to the command, which increase it's ability to spot things. These are the "--guess-foo" options. By default it will only list packages which are in the libraries section of the Debian archive, as these are the most likely candidates for removal.

In addition to showing removable library packages it allows you to display potentially orphaned data packages:

skx@lappy:~$ deborphan --guess-data
late-data

The manpage shows this option as well as other "guessing" options, and you can read it by invoking:

man deborphan

If you wish to see all the packages which aren't required you could run:

skx@lappy:~$ deborphan --guess-all
libxpm-dev
libxp-dev
xprt-xprintorg
libxrandr-dev
libxtst-dev
pm-dev
late-data
libjpeg-progs
libxmuu-dev
libxtrap-dev
libhtml-parser-perl
libxmu-dev

Most of the packages it reports are development packages, not required per se, but required if you wish to build things from source and link against package libraries.

As with most common jobs in Debian there are alternative methods of cleaning up your system, such as the cruft package.

Additionally some of the package managers such as aptitude and dselect allow you to handle orphaned packages - but I've always thought deborphan was a very underated tool!

 

 


Re: Removing unnecessary packages with deborphan
Posted by midget (80.202.xx.xx) on Thu 5 May 2005 at 18:58
You can also use debfoster for this :)

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Steve (82.41.xx.xx) on Thu 5 May 2005 at 18:59
[ View Weblogs ]

Because deborphan requires no setup phase I've always found it simpler to use.

Still each to their own - and like I said there are a few different ways of doing the same job! Steve
-- Steve.org.uk

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by midget (80.202.xx.xx) on Thu 5 May 2005 at 21:11
Well, is it safe to remove the packages listed by deborphan?

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Steve (82.41.xx.xx) on Thu 5 May 2005 at 21:18
[ View Weblogs ]

Yes.

Steve
-- Steve.org.uk

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (62.253.xx.xx) on Thu 5 May 2005 at 21:39
It might not always be safe to remove them blindly. For some reason, deborphan reports shellutils and textutils on my computer. These two are essential and should never be removed. So I always do the following (verbose and not elegant, but what else can I do?):
apt-get remove $(deborphan |grep -v shellutils |grep -v textutils)

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (83.194.xx.xx) on Fri 6 May 2005 at 16:40
You could simply add those packages to Deborphan's "white list": deborphan -A shellutils

Cheers
Julien

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (130.231.xx.xx) on Tue 10 May 2005 at 13:45
As safe as removing any package is. You should know what it is and what it's there for and decide if you want it based on that. It's not always a trivial decision, but you learn with time and you can just leave packages alone if you care more about not breaking your system somehow.
apt-cache show and apt-cache showpkg should give you good information about most packages.
Personally, I use and recommend deborphan. There, too, you don't have to make every decision immediately. See what commands you have at hand. I also turn on negative orphaning so it will keep removing packages that might come and go (some libraries and headers mostly).

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Serge (213.119.xx.xx) on Thu 5 May 2005 at 19:05
[ View Weblogs ]
Yep, I tend to run

apt-get remove `deborphan`


for this purpose.


--

Serge van Ginderachter


[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by TheHand (80.213.xx.xx) on Fri 20 May 2005 at 12:38
Thanks, removed 36MB of unused packages with this single command :)

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Qua (62.232.xx.xx) on Tue 13 Sep 2005 at 18:12
Heh, never though of that (albeit obvious now). Until now I was happy with typing the longer:

deborphan | xargs apt-get remove -y

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by clement (132.210.xx.xx) on Thu 5 May 2005 at 20:52
the orphaner package should also be interesting for this kind of task.

Cl�ment.

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (83.228.xx.xx) on Fri 6 May 2005 at 22:37
for i in `deborphan`; do apt-get --purge remove -y $i; done

works fine :]

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (82.41.xx.xx) on Fri 6 May 2005 at 22:51

Or:

dpkg --purge `deborphan`

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (62.175.xx.xx) on Fri 13 May 2005 at 17:56
deborphan | xargs apt-get --purge remove -y

is faster ;)

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by gonad (203.118.xx.xx) on Sat 7 May 2005 at 23:48
You mentioned cruft, which I had a look at once. Last changelog entry was in 2002 - does this mean the package is perfect or has it been neglected?

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Steve (82.41.xx.xx) on Sun 8 May 2005 at 01:50
[ View Weblogs ]

I think from looking at the cruft bug page it looks more neglected than perfect.

That's a shame, it's a long while since I used it but I do remember liking it at the time.

Steve
-- Steve.org.uk

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by sabin (81.223.xx.xx) on Sun 8 May 2005 at 16:23
[ View Weblogs ]
do you mean I can 'apt-get remove' files listed by deborphan or 'dpkg --purge' without any problems?
greets
./sabin -s

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Steve (82.41.xx.xx) on Sun 8 May 2005 at 16:30
[ View Weblogs ]

That's the intention, yes.

Althought it does make sense to look at the list and just check it first - in case it make some mistake.

Steve
-- Steve.org.uk

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by sabin (81.223.xx.xx) on Sun 8 May 2005 at 16:34
[ View Weblogs ]
ok that sounds very usefull to me. thanks, Steve

./sabin -s

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (192.38.xx.xx) on Tue 10 May 2005 at 11:18
apt-get remove --purge packageX

is a good alternative to

dpkg --purge packageX

is will remove (and purge) packages that require packageX.

[ Parent ]

Just use Aptitude
Posted by Anonymous (68.101.xx.xx) on Fri 13 May 2005 at 01:47
I used to worry about unused packages cluttering up my machine, too. I've used debfoster and deborphan, and was disappointed with both. How about a tool that remembers which packages were installed intentionally and which were pulled in just to satisfy dependencies?

Aptitude does it.

Just start using aptitude instead of apt-get. It can look exactly like apt-get from the command like, but it also has a curses UI mode that is very nice.

This link gives nine reasons to use aptitude instead of apt-get or dselect. IMHO, apt-get should be retired in favor of aptitude. It's just awesome.

http://lists.debian.org/debian-user/2004/04/msg11344.html

[ Parent ]

Re: Just use Aptitude
Posted by Anonymous (15.238.xx.xx) on Thu 9 Mar 2006 at 16:05
Is there a better word than `awesome'?
Aptitude is it.

[ Parent ]

`deborphan` != `deborphan --guess-all`
Posted by ptecza (193.0.xx.xx) on Tue 17 May 2005 at 08:41
Hi Steve!

deborphan man "says" that the tool invoked without any
options searchs orphaned packages _only within_ the libs
and oldlibs sections. I think it's important notice
information. Could you, please, add it?

Regards!

P.

[ Parent ]

Re: `deborphan` != `deborphan --guess-all`
Posted by Steve (82.41.xx.xx) on Tue 17 May 2005 at 09:12
[ View Weblogs ]

Thanks for the suggestion, I hope this updated version is better for you?

Steve
-- Steve.org.uk

[ Parent ]

Re: `deborphan` != `deborphan --guess-all`
Posted by ptecza (193.0.xx.xx) on Tue 17 May 2005 at 09:56
Thank you for the update! Yes, now the article is better :)

Regards!

P.

[ Parent ]

Polish translation
Posted by ptecza (193.0.xx.xx) on Tue 17 May 2005 at 10:24
of the article is out [1].

Best regards!

P.

[1] - http://www.debianusers.pl/article.php?aid=78

[ Parent ]

Re: Polish translation
Posted by Steve (82.41.xx.xx) on Tue 17 May 2005 at 10:26
[ View Weblogs ]

Thanks for taking the time to do this again, it's definitely appreciated.

I hope your users are greatful :)

Steve
-- Steve.org.uk

[ Parent ]

Re: Polish translation
Posted by ptecza (193.0.xx.xx) on Tue 17 May 2005 at 10:49
I thank you for the advisable article! It was a pleasure
for me :)

My users don't send me free beer, but they will get next
your articles soon :D

P.

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (205.200.xx.xx) on Sun 29 May 2005 at 17:52
If you use Synaptic for package management, you can get a list of orphaned packages by clicking (in recent versions) on "Custom" button at the lower left, and then choose "Orphaned" from the list of custom filters.

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (38.117.xx.xx) on Sun 17 Jul 2005 at 21:10
trying deborphan, on my 99% Sarge desktop, I get:
  • libgcrypt1
  • libtasn1-0
  • libident
  • libavcodec1
  • libavcodec2
  • liba52-0.7.4
  • libfame-0.9
  • libnfsidmap1
  • libxmltok1
    but using my preferred package management frontend of synaptic, I click on "custom", and there is no "orphaned".

    Being somewhat familiar with how synaptic works, nothing appears under "orphaned" because synaptic doesn't see anything orphaned (that's how it works with the other options at least).

    And while we're at it, taking a look at one of my servers (where space is extremely tight, a former Mepis install that has been apt-get updated and apt-get upgraded to debian-sarge for the past year, with everything Mepis I'm aware of removed, and yes, I have X installed, I need Mozilla composer, konqueror and other X apps on the box from time to time), deborphan shows:
  • libgtkspell0
  • libhk-classes-mysql
  • libid3-3.8.3
  • libhk-classes6
  • libhowl0
  • libflac++2c102
  • dbus-glib-1
  • libavcodec1
  • libgdk-pixbuf2
  • termcap-compat
  • libgtkmm2.0-1c102
  • libdns11
  • libkeynote0
  • j2re1.4
  • libqt3-i18n
  • libtiff3g
  • libieee1284-3
  • libgnet2.0-0
  • libarts1-audiofile
  • libexif9
  • libcurl2
  • libijs-0.35
  • libmysqlclient10
  • libgssapi1-heimdal
  • libpisock8
  • lesstif1
  • libreiserfs0.3-0
  • libzvt2.0-0
  • libwxgtk2.5.3
  • libtag1
  • libgnutls7
  • libwxgtk2.4
  • libmimelib1a
  • plib1.8.3
  • libmyspell3
  • libneon23
  • libnet0
  • libstlport4.6
  • libgnutls10
    but nothing under "orphaned" (although I have a long list under "broken" which I'm thinking is because I have something missing from my sources list which I'm checking now, the packages listed in broken are up to date, nothing gets fixed with "fix broken packages", and everything is working ok).

    So other than googling, any shortcuts to finding out whether its ok to remove all the packages above?

    The desktop, I see libavcodec1, libavcodec2, aren't these part of the mplayer install? (mplayer happens to update/upgrade against all, stable, testing, unstable so I get the latest codecs and mplayer packages)

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (38.117.xx.xx) on Sun 17 Jul 2005 at 21:18
I'm the top poster. Just checked my sources lists, everything is ok. Don't have an explanation why the server shows a large number of packages as broken using synaptic. The broken packages include apache, and there's nothing wrong with apache, 1.3.33-6. (sarge), or the other packages in the list from what I can tell.

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by VidJa (131.174.xx.xx) on Wed 14 Sep 2005 at 08:07
I used this indeed some time ago (around may 2005), but after several updates the option seems to be lost from Synaptic, any hints how to get it back?

[ Parent ]

Purge configuration files
Posted by Anonymous (129.116.xx.xx) on Mon 1 May 2006 at 19:07
Well, I jumped the gun and removed a lot of packages that I intended to purge. Now I'm stuck with all of the configuration files. Is there a way to purge after the packages have been removed?

[ Parent ]

Re: Purge configuration files
Posted by Steve (82.41.xx.xx) on Mon 1 May 2006 at 19:08
[ View Weblogs ]

Find the list of removed packages by running:

COLUMNS=200 dpkg --list |grep ^r

Or just their names:

COLUMNS=200 dpkg --list |grep ^r | awk '{print $2}'

Steve

[ Parent ]

Re: Purge configuration files
Posted by Anonymous (24.85.xx.xx) on Fri 25 Jan 2013 at 19:36
You can do:
dpkg -P $(COLUMNS=200 dpkg --list |grep ^r|awk '{print $2}')
It purges the config files of removed packages

[ Parent ]

do it multipe times!!!
Posted by Anonymous (88.77.xx.xx) on Wed 27 Jun 2007 at 18:38
Hi, it is ok to try

aptitude purge `deborphan [--guess-all]`

several times, as removed packages may leave some more packages orphaned...

keep up the good work!

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by jamesm (203.214.xx.xx) on Fri 24 Dec 2010 at 12:55
Whats wrong with `aptitude autoclean`? it works, does it not remove these kind of packages?

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (175.39.xx.xx) on Fri 4 Nov 2011 at 01:03
man aptitude:
autoclean - Removes any cached packages which can no longer be downloaded.

Autoclean doesn't remove installed packages, just .deb files from the apt cache

[ Parent ]

Re: Removing unnecessary packages with deborphan
Posted by Anonymous (24.85.xx.xx) on Fri 25 Jan 2013 at 19:32
You mean apt-get autoremove
I use it regularly, but deborphan still found stuff.

[ Parent ]