fbpx dpkg Command on Linux: Install, Remove, List .deb Packages | Certificação Linux

dpkg Command on Linux: Install, Remove, and Manage .deb Packages

📅 01/01/2019 ⏱ 4 min ✍️ Uira Ribeiro
Linuxcommands
dpkg Command on Linux: Install, Remove, and Manage .deb Packages
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The dpkg utility is responsible for package management in Debian systems.

dpkg is the base command for manipulating Debian packages in systems based on this Distribution family. If you have .deb packages, dpkg is what allows installation or analysis of their contents.

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

Thus, if you need to manually download a ".deb package", you will need to handle it with dpkg.

And 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 most automated way possible.

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

According to the Debian Wiki, it is responsible for the low-level maintenance of packages in the system.

The most frequent options are:

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

The most frequent actions are:

  • -i packagename: Installs the packagename package. This process involves making backup copies of old files that already exist in the system, unpacking, installation and configuration. This action can also be referenced with –install packagename;
  • -l searchkey: Lists the information of packages that contain the same search key in the name;
  • -L packagename: Lists the files installed by the packagename package;
  • --print-avail  packagename: 'Lists all available information about the packagename package in /var/lib/dpkg/available;
  • --purge packagename: Removes the entire packagename package;
  • -r packagename: Removes all files of the package, except the configurations;
  • -s packagename: Shows the status of the package;
  • -S file: Searches for a file in installed packages;
  • --unpack packagename: Unpacks a package, but does not install;
  • --configure packagename: Configures an unpackaged package.

Examples:

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

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

Completely removes the ace-of-penguins_1.2-3_i386.deb package from the system.

# 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

dpkg can also be used to find out which package a given file belongs to with the "-S" option (uppercase):

# 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 "-s" (lowercase) option of dpkg can be used to view information about a specific package:

$ dpkg -s coreutils
Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utils
Installed-Size: 15719
Maintainer: Michael Stone <[email protected]>
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 find the packages installed on the system from a key:

# dpkg -l | grep mozilla
     ii  mozilla-browse 0.9.6-7        Mozilla Web Browser

The file /etc/dpkg/dpkg.cfg contains the default options when dpkg is executed.

The dpkg control files reside in the directory /var/lib/dpkg. Two interesting files in this directory are:

  • /var/lib/dpkg/available: List of available packages;
  • /var/lib/dpkg/status: Status of installed packages. Reports when they were installed, removed, etc.

The dpkg command can also be used to unpack a package, so that it is possible to see 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 (2.8.5-2) over (2.8.5-2)…
Processing triggers for MIME support (3,62)…

This command is not widely used 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 enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp