dpkg Command in Linux: Install and Manage Debian Packages

By 

Published on

5 min read

dpkg package management cards for installing, querying, and removing deb packages

When you install software on Ubuntu or Debian with apt , the package manager quietly calls dpkg in the background to do the actual work. dpkg is the low-level tool that unpacks and installs .deb files, maintains the package database, and handles removal and purging. Knowing how to use it directly is useful when you have a local .deb file that is not in a repository, when you need to query what files a package installed, or when you want to find which package owns a specific file on your system.

Syntax

txt
dpkg [OPTIONS] COMMAND [ARGUMENTS]

Install, remove, purge, and configure operations require sudo because they modify system directories and the package database. Query commands such as dpkg -l, dpkg -L, dpkg -S, and dpkg -s usually run without elevated privileges.

Install a Package

To install a local .deb file:

Terminal
sudo dpkg -i package.deb

dpkg unpacks the archive, runs the maintainer scripts, and registers the package in its database. If the package has unmet dependencies, the install fails with a dependency error. Fix it by running:

Terminal
sudo apt install -f

apt install -f (fix broken) resolves and installs any missing dependencies, then completes the pending dpkg installation.

For most local .deb installs, apt install ./package.deb is easier because it can resolve dependencies in the same step. Use dpkg -i when you specifically need the lower-level package operation.

Remove a Package

To uninstall a package while keeping its configuration files:

Terminal
sudo dpkg -r package-name

To uninstall a package and delete its configuration files at the same time (a full purge):

Terminal
sudo dpkg -P package-name

Use -P when you want a clean removal with no leftover config, or when you plan to reinstall with a fresh configuration.

List Installed Packages

To list every installed package with its version and status:

Terminal
dpkg -l

The output is wide. Each package line starts with three status columns: desired action, current package status, and error state. The normal installed state appears as ii, followed by the package name, version, architecture, and description:

output
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version       Architecture Description
+++-==============-=============-============-=================================
ii  curl           8.5.0         amd64        command line tool for transferring data
ii  nginx          1.26.0        amd64        small, powerful, scalable web/proxy server

The first i means the package is selected for installation, and the second i means it is installed and configured. Filter by name to narrow the output:

Terminal
dpkg -l 'nginx*'
output
ii  nginx          1.26.0  amd64  small, powerful, scalable web/proxy server
ii  nginx-common   1.26.0  all    small, powerful, scalable web/proxy server (common files)

List Files Installed by a Package

To see every file a package placed on your system:

Terminal
dpkg -L nginx
output
/.
/etc
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/sites-available
/etc/nginx/sites-enabled
/usr/sbin
/usr/sbin/nginx
...

This is useful when you need to find where a package installs its binary, config files, or documentation.

Find Which Package Owns a File

To identify which package installed a particular file:

Terminal
dpkg -S /usr/sbin/nginx
output
nginx: /usr/sbin/nginx

You can also search by pattern:

Terminal
dpkg -S '*/bin/curl'
output
curl: /usr/bin/curl

Show Package Details

To print the full metadata for an installed package including version, dependencies, and description:

Terminal
dpkg -s nginx
output
Package: nginx
Status: install ok installed
Priority: optional
Section: web
Installed-Size: 47
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 1.26.0-1ubuntu1
...

Inspect a .deb File Without Installing

To read the metadata of a .deb file before installing it:

Terminal
dpkg --info package.deb
output
 new Debian package, version 2.0.
 size 1234567 bytes: control archive=2048 bytes.
     ...
 Package: myapp
 Version: 2.1.0
 Architecture: amd64
 ...

To list the files the package would install without actually installing it:

Terminal
dpkg --contents package.deb

Extract a Package Without Installing

To unpack the contents of a .deb file into a directory for inspection:

Terminal
dpkg -x package.deb /tmp/extracted

The directory structure mirrors where files would be installed on the real system.

Export and Restore Package Selections

To export a list of all installed packages (useful for replicating a system):

Terminal
dpkg --get-selections > installed-packages.txt

To restore those selections on another machine:

Terminal
sudo dpkg --set-selections < installed-packages.txt
sudo apt-get dselect-upgrade

Reconfigure an Installed Package

Some packages run interactive setup at install time. To run that setup again:

Terminal
sudo dpkg-reconfigure package-name

This is commonly used to reconfigure tzdata for timezone changes, keyboard-configuration, or locales.

Fix Broken Package State

If a system update or manual operation leaves packages in a half-installed or unconfigured state, run:

Terminal
sudo dpkg --configure -a

This processes any pending package configuration steps. Follow it with sudo apt install -f if dependency issues remain.

Troubleshooting

dpkg reports dependency problems
dpkg installs the package file you give it, but it does not download missing dependencies. Run sudo apt install -f to install the required packages and finish the pending configuration.

A package operation was interrupted
If an update or install stopped before configuration finished, run sudo dpkg --configure -a. This resumes pending package configuration scripts.

dpkg cannot find a package
Use the installed package name, not the .deb filename. Run dpkg -l 'pattern*' to find matching installed packages, then use that package name with commands such as dpkg -L, dpkg -s, or sudo dpkg -r.

Quick Reference

For a printable quick reference, see the dpkg cheatsheet .

CommandDescription
dpkg -i pkg.debInstall a local .deb file
dpkg -r packageRemove a package, keep config
dpkg -P packagePurge a package and its config
dpkg -lList all installed packages
dpkg -l 'pattern*'Filter installed packages
dpkg -L packageList files installed by a package
dpkg -S /path/to/fileFind which package owns a file
dpkg -s packageShow package status and details
dpkg --info pkg.debInspect a .deb file
dpkg --contents pkg.debList files in a .deb
dpkg -x pkg.deb /dirExtract a .deb without installing
dpkg --get-selectionsExport installed package list
dpkg-reconfigure packageRe-run package configuration
dpkg --configure -aFix incomplete installations

Conclusion

dpkg is the foundation of package management on Debian-based systems. For everyday installs and updates from repositories, apt is the better tool because it resolves dependencies automatically. Reach for dpkg directly when you need to install a .deb file from disk, audit what a package installed, or diagnose a broken package state.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page