Master the Linux ‘dpkg’ Command: A Comprehensive Guide

Peter Hou
3 min readJun 19, 2023

--

This guide provides an in-depth exploration of the dpkg command in Linux, intended to equip newbies with a thorough understanding of this tool. It covers the command's history, usage, and parameters while offering practical examples, tricky skills, and precautionary notes. The guide concludes with a discussion of its limitations and overall capabilities.

Instructions

This comprehensive guide is designed to help you fully understand the usage, functionality, and intricate details of the dpkg command in Linux. We will cover its history, when and why to use it, common use cases, and delve into its most commonly used and other supported parameters. Furthermore, we will provide examples of its application and mention some tricky skills along with precautionary notes.

History

dpkg, short for Debian package, is a tool to install, build, remove and manage Debian packages. It was first used in the Debian software distribution, which was created by Ian Murdock in 1993. It remains integral to managing software on Debian-based distributions like Ubuntu.

When and why to use it

dpkg is used to manage .deb packages. It can install, remove, and provide information about .deb packages. It is particularly useful when a user wants to install packages downloaded from sources other than the default package manager or repositories, or if the user needs to manually manage specific software.

How to use it

The dpkg command is primarily used through the command line interface. For instance, to install a package, you would use the -i flag followed by the package name.

$ sudo dpkg -i package.deb
(Reading database ... 123456 files and directories currently installed.)
Preparing to unpack package.deb ...
Unpacking package (1.0-1) ...
Setting up package (1.0-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

The commonly used parameters

Here are some of the commonly used parameters for dpkg:

  • -i or --install: this parameter is used to install a package.
$ sudo dpkg -i package.deb
Setting up package (1.0-1) ...
  • -r or --remove: this parameter is used to remove a package.
$ sudo dpkg -r package
(Reading database ... 123456 files and directories currently installed.)
Removing package (1.0-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

Other supported parameters

There are many other parameters supported by dpkg, including but not limited to:

  • -C or --audit: Checks for partially installed packages.
  • -l or --list: Lists installed packages.
  • -s or --status: Shows the status of a package.
  • --unpack: Unpacks the package, but does not configure it.
  • --configure: Configures a package which has been unpacked but not yet configured.
  • -P or --purge: Removes a package including its configuration files.

Most common use cases

One of the most common use cases for dpkg is installing a .deb package that has been downloaded from the internet:

$ sudo dpkg -i downloaded-package.deb
Selecting previously unselected package.
(Reading database ... 123456 files and directories currently installed.)
Preparing to unpack downloaded-package.deb ...
Unpacking package (1.0-1) ...
Setting up package (1.0-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

The tricky skills

One of the tricky things to note about dpkg is that it doesn't handle dependencies. If you're installing a package that has unmet dependencies, you can use apt-get -f install to fetch those dependencies after running dpkg.

$ sudo dpkg -i package-with-dependencies.deb
dpkg: dependency problems prevent configuration of package-with-dependencies:
package-with-dependencies depends on dependency1; however:
Package dependency1 is not installed.
$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done

What needs to be noted

One important thing to note about dpkg is that it does not handle dependencies on its own. You might need to resolve dependencies using apt-get -f install after using dpkg. Also, it is recommended to use sudo while using dpkg command to avoid permission issues.

Conclusion

The dpkg command is a powerful tool for managing software on any Debian-based system. With it, you can install, remove, and inspect .deb packages. Though it doesn't handle dependencies, this functionality can be supplemented by tools like apt-get.

--

--

Peter Hou

I am a Senior Software Engineer and tech lead in a top tech company.