Skip to content

Managing Debian Packages


This post contains content and examples originally found at an article on ServerWatch. It contains some notes and tips about the Debian packaging system, with some commands beyond the usual, everyday ones that somebody might use. One thing that is often useful is to know why a package was installed. To find out, we want to use the aptitude utility, which will provide this very easily and quickly. Use aptitude why packagename to find out what package requires or suggests the package.

Occasionally, you must know what package a file belongs to, or what files are in a package. For a file that’s installed, use dpkg -S filename or apt-file search filename. For example, if you don’t have Sendmail installed and want to know what package owns the symlink for /usr/lib/sendmail, you can run dpkg -S /usr/lib/sendmail. In my case, this returns:

   postfix: /usr/lib/sendmail

What if you want to know what package would install a file? That’s a job for apt-file. Note that this utility may not be installed by default. You’ll also need to update its cache by running apt-file update. Then run apt-file filename that you want to see. The more specific you can be, the better. If you look for a single string that’s likely to be in many filenames (like “vim“), you’ll get quite a few results. If you look for something very specific like /usr/lib/, then it will provide only one result. So if I search for /etc/apache2/apache2.conf even on a system without Apache installed, it will tell me that the package I’m looking for is apache2.2-common.

Last, but definitely not least, let’s look at saving a list of all installed software. Say you want to do a clean install of Debian (or a Debian derivative) to upgrade rather than apt-get dist-upgrade, but you don’t want to figure out by trial and error what packages you had before — simply run dpkg --get-selections, and you’ll see a full list of packages that are installed. Also, dpkg -l will provide a detailed and documented list of installed packages (together with their description and other information).

But what about restoring the packages? That’s easy. Run dpkg --get-selections > installed-packages.txt. When you have the clean system, run dpkg --set-selections < installed-packages.txt. Do be sure to back this file up before doing the install, of course.

Leave a Comment

What do you think?

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

You are commenting using your 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: