Debian Package Manager: Managing .deb Packages with dpkg
Learn how to use dpkg to install, remove, purge, list, and inspect Debian .deb packages, plus repair dependencies with APT.
dpkg is the low-level package management command used by Debian and Debian-based Linux systems. It can install a local .deb file, remove software, list package records, and inspect package information. Because dpkg does not download or resolve dependencies, you will often use an APT command alongside it.
This lesson assumes familiarity with Linux command-line basics, files and directories, and running commands with sudo. For help locating files and commands, see showing the full path of shell commands.
What Debian packages are
A Debian package is a software package built for Debian-family systems. It contains program files, package metadata, and instructions that help the operating system install and track the software.
A Debian package is normally distributed as a package archive with the .deb filename extension. For example:
example-app_1.0_amd64.deb
The filename commonly includes the package name, version, and processor architecture. The filename is not necessarily the same as the installed package name. In this example, the installed package name might be example-app.
Debian uses this format, as do Debian-based distributions such as Ubuntu, Linux Mint, and Knoppix. These systems also provide higher-level APT tools for working with repositories and dependencies.
What dpkg does
dpkg is the low-level Debian package management utility. It works directly with local package archives and the system's package database.
- Install a locally downloaded
.debarchive. - Remove or purge an installed package.
- List package records known to the system.
- Display status and metadata for an installed package.
- Display metadata stored inside a local package archive.
Operations that change installed software generally require administrator privileges. On a typical desktop system, place sudo before the command. Query commands such as dpkg -l, dpkg -s, and dpkg -p usually do not require sudo.
Installing a local .deb package
Use the -i option, short for install, followed by the path to the package archive:
sudo dpkg -i ./example-app_1.0_amd64.deb
The ./ means that the file is in the current directory. If it is elsewhere, provide a relative or complete path:
sudo dpkg -i /home/alex/Downloads/example-app_1.0_amd64.deb
dpkg unpacks the archive and attempts to configure the package. If the package requires another package that is not installed, dpkg cannot obtain that dependency itself. The installation may finish with dependency errors, and the new package can remain in an unpacked or unconfigured state.
Repairing dependencies after dpkg
A dependency is another package required for software to install or function correctly. APT, the Advanced Package Tool, is the higher-level package management system that downloads packages from configured repositories and resolves dependencies.
After dpkg reports missing dependencies, use one of these repair commands:
sudo apt-get -f install
sudo apt --fix-broken install
apt-get -f install is the traditional, script-oriented form. apt --fix-broken install is the modern equivalent. The command may download missing packages, configure unpacked packages, or propose package removals to make the package system consistent.
Removing installed packages
Use dpkg -r, followed by the installed package name:
sudo dpkg -r example-app
Standard removal normally deletes the package's program files but leaves system-wide package configuration files. This can preserve settings if you reinstall the package later.
To remove the package and its package-managed configuration files, use dpkg -P. The -P option performs a purge:
sudo dpkg -P example-app
Use the installed package name, not the downloaded filename. For example, example-app is a package name, while example-app_1.0_amd64.deb is a package archive filename. If you are unsure of the package name, find it with dpkg -l.
Listing installed and known packages
Run dpkg -l to display package records:
dpkg -l
The output includes a status area near the left side. The first two status characters represent the desired and current package states:
ii: the package is desired for installation and is currently installed and configured.rc: the package has been removed, but package-managed configuration files remain.un: dpkg has no installed record for the package, or it is not currently selected for installation.
Some output also includes a third character for an error or special state. The exact columns and descriptions are shown in the command's header and may vary slightly by dpkg version. For routine checks, ii indicates a normally installed package and rc indicates residual configuration.
Filter the listing by a package-name pattern:
dpkg -l 'example*'
Keep the pattern in single quotes so that the shell does not expand the asterisk against filenames in the current directory. dpkg then applies the pattern to package names.
Viewing package information and status
Inspecting an installed package with dpkg -s
Use dpkg -s with an installed package name to view its status and metadata:
dpkg -s bash
The output can include the package status, version, architecture, dependencies, maintainer information, and description. This operation queries the package database for a package installed or otherwise recorded on the system.
Inspecting a local archive with dpkg -p
Use dpkg -p with a path to a local .deb file:
dpkg -p ./example-app_1.0_amd64.deb
This reads metadata stored inside the package archive without requiring the package to be installed. It is useful for checking the archive's version, architecture, dependencies, and description before installation.
The distinction is important:
dpkg -s package-namequeries an installed package record.dpkg -p ./package-file.debexamines metadata inside a local package archive.
Common dpkg operations
dpkg and APT responsibilities
dpkg and APT complement each other rather than serving exactly the same role.
apt-get is a script-oriented APT command used for installation, updates, removal, and dependency repair. aptitude is another higher-level Debian package management interface with dependency-resolution features. All of these tools use repositories when they need to download packages; a repository is a configured software source containing packages and package metadata.
Troubleshooting dpkg
Dependency errors or an unconfigured package
Symptom: installation ends with dependency errors, or dpkg says a package is unpacked but not configured.
Cause: dpkg processed the local archive but does not retrieve required dependency packages.
Resolution: run sudo apt-get -f install or sudo apt --fix-broken install. Review the proposed changes before confirming.
dpkg cannot find the .deb file
Cause: the filename or path is wrong, or the command is being run from a different directory.
ls ./example-app_1.0_amd64.deb
If the file is not found, change to the directory containing it or provide its complete path. A relative path such as ./package-file.deb explicitly refers to the current directory.
Removal says the package is not installed
You may have supplied the archive filename instead of the installed package name, or the package may already be absent. Search the records:
dpkg -l 'example*'
Then use the package name shown in the listing with dpkg -r or dpkg -P.
A removed package still appears in the listing
A standard removal can leave configuration files, producing an rc record. If those package-managed configuration files should also be removed, run:
sudo dpkg -P package-name
Permission denied or an administrative lock
Package changes require administrator access, so retry with sudo. An administrative lock can also mean that another package management process is active. Wait for the other process, such as a graphical software updater, to finish before retrying. Do not delete lock files manually.
The information option does not show what you expected
Use dpkg -s for an installed package name and dpkg -p for a local .deb archive. Supplying the wrong kind of input is a common reason for confusing results or an error.
Exam-relevant summary
- A Debian package is normally a
.debpackage archive used by Debian, Ubuntu, Linux Mint, Knoppix, and related distributions. - dpkg is the low-level tool for installing local archives, removing packages, listing records, and inspecting package data.
sudo dpkg -i ./package.debinstalls a local archive but does not resolve dependencies.sudo dpkg -r package-nameremoves software while normally retaining configuration files.sudo dpkg -P package-namepurges the package and its package-managed configuration files.dpkg -llists package records;iicommonly indicates installed and configured, whilercindicates removed with residual configuration.dpkg -s package-namequeries an installed package;dpkg -p ./package.debexamines a local archive.- APT is the higher-level system that downloads packages from repositories and resolves dependencies.
- After a dependency failure, use
sudo apt-get -f installorsudo apt --fix-broken install, and inspect the proposed changes before confirming.