May 302013
Article Server Administration

This post explains some of the commands available for the management of software packages in a Debian system.

How to get a list of installed packages

The command “dpkg -l” outputs a list of the installed packages, showing their status, name, version architecture and a brief description:

The status of the packages is encoded in the first three characters, as follows:

  • Column 1 – Acción deseada
    • u = Unknown
    • i = Install
    • h = Keep
    • r = Remove
    • p = Purge
  • Column 2 – Status del paquete
    • n = Not installed
    • c = Only the configuration files for the package are present
    • H = Half-installed
    • U = Unpacked
    • F = Half-configured
    • W = Waiting for triggers
    • t = Pending for triggers
    • i = Installed
  • Column 3 – Error indicator
    • <empty> = (no error)
    • R = Re-installation required

The first three characters for most packages will be “ii “, meaning:

– The desired status for the package is “installed”

– The package is actually installed in the system

– There are no errors, there is no need to reinstall the package.

The list can be filtered using “grep”, to list packages that are not in status “ii “:

In the example above, the package libapache2-mod-php5 has an status “rc “, meaning that it should be removed from the system, but there are still some configuration files for that package in the system. Other than that, there is no error (the third character is a space character). In this case, the configuration files can be deleted with the command “apt-get purge”, as explained below.

How to install and uninstall packages

the “apt-get” command is normally used in a Debian system to perform these tasks, as shown in the following examples

  • Install package1 and package2
  • Install version 2.3 of package1:
  • Uninstall package1 and package2
  • Completely uninstall package1 and package2, removing configuration files for those packages

How to update packages

Before updating a package, the “apt-get update” command show be executed to update the list of available packages and their versions:

Next, if we want to update a given package to the most recent version available, we just issue the command “apt-get install package”, as if the package was being installed for the first time.

If we want to update all installed package, we issue the command “apt-get upgrade”. This command does not install any new package nor unsintalls any previously installed package, it just updates the existing packages. It the update of a given package would require installing or uninstalling other packages, “apt-get upgrade” will leave the package at its current version.


As can be seen in the last lines of the output from the “apt-get upgrade” in the example above, 201 MB will need to be downloaded, but the final result will be that 17.4 MB will be freed. This may happen if old versions of some packages are replaced with new versions that take up less space.

How to downgrade a package to an older version

Sometimes, the most recent version of a package may have compatibility issues with some applications that were developed for previous versions of that package. In those cases, it is possible to revert to a previous version.

First, we need to remove the package using “apt-get remove” or “apt-get purge”. Then, the older version is installed as follows:

Next, we should use the command “dpkg –set-selections” to tell the system that this package should not be updated, even if a bulk upgrade is performed by running “apt-get upgrade” or some other command:

How to find out which files make part of a package

The “dpkg -L PACKAGE” command lists the files included in an installed package. For instance:

If the package is not installed in the system, the command “apt-file list PACKAGE” can be used instead. Previously, the  “apt-file update” needs to be reun to load the information in cache

In this example we can see that “apt-file list” returns information about the most recent version of the package available in the repositories (version 2.9 of abiword in the above example).  The command “dpkg -L” returns the information for the installed version of the package (abiword 2.8 in the example).

How to tell which package does a file belong to

If the file is installed in the system, the command “dpkg -S” can be used for this. Example:

The output from the command shows that the “/bin/ls” command is part of the “coreutils” package.

If the file is not installed in the system, “apt-file search” can be used to perform a search in the repositories. Example:

The “apt-file search” command searches any line in the content of each package that includes the string “/bin/ls”. For this reason, it may return many unrelated results. Among them, however, we can find the one we were looking for: “coreutils: /bin/ls”.

 Posted by at 4:01 pm

 Leave a Reply