I have to confess that, for a long time, I was a big Debian fan; this changed when I switched to the BSDs, but I still think that it is (one of) the best GNU/Linux distribution. This, and because its excellent hardware support, is why it's the main system on my iBook G3.
As a user, it's very common to install lots of packages just to try them, followed by a quick deinstallation when you realize they don't suit your needs. Unfortunately, following common procedures often leaves useless garbage in the file system.
The first annoying thing are installed packages that provide libraries but which aren't used by any other package. These are often called orphan packages and can be listed by using the deborphan utility (which must be installed first). Assuming you have it, do the following to remove all orphaned libraries:
# dpkg --purge $(deborphan)Note that this in turn may obsolete other libraries, so rerun this command until deborphan prints nothing. Also, please bear in mind that this is dangerous if you have installed software from other means — not from Debian packages — as those libraries may still be used.
Then we have obsolete configuration files. Whenever you remove a package, all its files are removed except the configuration ones, in case you did some modification you want to preserve during an eventual reinstallation. This may be OK in some scenarios but, personally, when I delete something I want it really gone. Here comes dpkg's --purge option to help, which removes all leftovers of a previously installed package.
But how to purge all configuration files from packages that were once installed? Just do the following:
# dpkg --purge $(dpkg --list | grep ^rc | awk '{ print $2; }')This constructs a list of packages which are removed but still have their configuration files installed (denoted by the ^rc pattern) and passes this list to the package management utility to purge all obsolete files.
Hi jmmv
ReplyDeleteI have been playing with ubuntu a bit recently so this tip really came in handy. Are there any similar tips applicable to NetBSD I wonder?
I'm not aware of any way to look for "orphaned" packages in pkgsrc, but it shouldn't be too difficult to implement such an utility.
ReplyDeleteAs regards configuration files, pkgsrc automatically removes all of those which were not manually edited. That is, it only keeps the ones that you touched, leaving as less stale files as possible.
Thanks for your reply, jmmv. Well, to answer my own question, I just remembered that wip/pkgmanager searches for and removes orphaned packages. Have you tried it? I think it's great - see http://www.scode.org/pkgmanager/
ReplyDeleteAs for config files, it's good to know that pkgsrc takes care of the 'virgin' ones anyway.
I haven't tried pkgmanager, but might take a look. Thanks for the info.
ReplyDeletewhen using the command:
ReplyDeletedpkg --purge $(dpkg --list | grep ^rc | awk '{ print $2; }')
any packages that have a name longer then 14 characters is not removed.
ie:
:~/deb# dpkg --purge gnome-control-
dpkg - warning: ignoring request to remove gnome-control- which isn't installed.
Any suggestions?
I found an answer for my own question...
ReplyDeleteThe COLUMNS=132 will change the default column of 14 to a very roomy 132 characters....
dpkg --purge $(COLUMNS=132 dpkg -l | grep ^rc | awk '{ print $2; }')
Nice to know this still works like a charm two years later.
ReplyDeleteExactly what I was looking for, so that "dpkg --list>dpkg.txt" isn't soo bloated.