Skip to content

dpkg command on Linux (package management)

The dpkg utility is responsible for managing packages on Debian systems.

The dpkg is the base command for manipulating Debian packages on systems based on this family of distributions. If you have pacotes.deb, it is the dpkg that allows the installation or analysis of your content.

But this program only has a partial view of Debian package management: it knows what is installed on the system, and whatever is entered on the command line, but it knows nothing about the other packages available.

So, if you need to manually download a “pacote.deb” to manipulate it with dpkg.

Also, dpkg will fail if a dependency is not met during a package installation. Tools like apt and aptitude, on the other hand, will create a list of dependencies to install everything in the way as automated as possible.

The dpkg stores the information of the packages installed mainly in the /var/lib/dpkg/available and /var/lib/dpkg/status files. These files contain the list of available packages and status, respectively.

According to the Debian Wiki, it is responsible for maintaining the packages on the system at a low level.

The most common options are:

  • -E: This option does not rewrite an already installed package of the same version;
  • -G: This option does not rewrite an already installed package, even if it is older;
  • -R: Processes all packages found in a given directory recursively.

The most frequent actions are:

  • -i package-name: Installs the package package-name. This process involves backing up old files that already exist on the system, unpacking, installing, and configuring. This action can also be referenced with —install package-name;
  • -l search key: Lists package information containing the same search key in the name; -L packagename
  • : Lists the files installed by the package-name package package package;
  • —print-avail packagename: ‘Lists all available information about the packagename package in /var/lib/dpkg/evaluable;
  • —purge packagename: Removes the entire package package-name;
  • -r package-name: Removes all package files, except settings;
  • -s
  • packagename: Shows package status;
  • -S file: Search for a file in installed packages; —unpack packagename: Unpacks a package but does not install; - —configure packagename: Configures an uninstalled package.

Examples:

Install the acct_6.3.5-32_i386.deb package.

# dpkg -i acct_6.3.5-32_i386.deb

Removes the ace-of-penguins_1.2-3_i386.deb package from the system completely.

# dpkg --purge ace-of-penguins_1.2-3_i386.deb

Configures the abook_0.4.16-1_i386.deb package.

# dpkg --configure abook_0.4.16-1_i386.deb

The dpkg can also be used to find out which package a particular file belongs to with the “-S” option (capital letters):

# dpkg -S stdio.h
libc6-dev: /usr/include/stdio.h
libc6-dev: /usr/include/bits/stdio.h
perl: /usr/lib/perl/5.6.0/core/nostdio.h

The dpkg “-s” (lowercase) option can be used to view information for a particular package:

$
``` <strong><code>dpkg -s coreutils</code></strong>

Package: coreutils Essential: yes Status: install ok installed Priority: required Section: useful Installed Size: 15719 Maintainer: Michael Stone Architecture: amd64 Multi-Arch: Foreign Version: 8.30-3 Pre-Depends: libacl1 (>= 2.2.23), libattr1 (>= 1:2 .4.44), libc6 (>= 2.28), libselinux1 (>= 2.1.13) Description: GNU core utilities This package contains the basic file, shell and text manipulation utilities which are expected to exist on every operating system.

Another possibility is to discover the packages installed on the system from a key:

dpkg -l | grep Mozilla

ii mozilla-browse 0.9.6-7 Mozilla Web Browser

The /etc/dpkg/dpkg.cfg file contains the default options when dpkg is executed.
The dpkg control files reside in the **/var/lib/dpkg** directory. Two interesting files in this directory are:
- /var/lib/dpkg/available: List of available packages;
- /var/lib/dpkg/status: Status of installed packages. It tells you when they were installed, removed, etc.
The dpkg command can also be used to unpack a package so that you can view its contents.

$ dpkg —unpack man-db_2.8.5-2_amd64.deb

(Reading database... 14937 files and directories currently installed.)
Preparing to unpack man-db\_2.8.5-2\_amd64.deb...
Unpacking man-db (2.8.5-2) about (2.8.5-2)...
Processing triggers for MIME support (3.62)... ```

This command is not used much in practice, since the apt or apt-get commands are much easier to use.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.