dpkg Command in Linux: Install and Manage Debian 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
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:
sudo dpkg -i package.debdpkg 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:
sudo apt install -fapt 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:
sudo dpkg -r package-nameTo uninstall a package and delete its configuration files at the same time (a full purge):
sudo dpkg -P package-nameUse -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:
dpkg -lThe 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:
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 serverThe 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:
dpkg -l 'nginx*'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:
dpkg -L nginx/.
/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:
dpkg -S /usr/sbin/nginxnginx: /usr/sbin/nginxYou can also search by pattern:
dpkg -S '*/bin/curl'curl: /usr/bin/curlShow Package Details
To print the full metadata for an installed package including version, dependencies, and description:
dpkg -s nginxPackage: 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:
dpkg --info package.deb 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:
dpkg --contents package.debExtract a Package Without Installing
To unpack the contents of a .deb file into a directory for inspection:
dpkg -x package.deb /tmp/extractedThe 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):
dpkg --get-selections > installed-packages.txtTo restore those selections on another machine:
sudo dpkg --set-selections < installed-packages.txt
sudo apt-get dselect-upgradeReconfigure an Installed Package
Some packages run interactive setup at install time. To run that setup again:
sudo dpkg-reconfigure package-nameThis 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:
sudo dpkg --configure -aThis processes any pending package configuration steps. Follow it with sudo apt install -f if dependency issues remain.
Troubleshooting
dpkg reports dependency problemsdpkg 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 .
| Command | Description |
|---|---|
dpkg -i pkg.deb | Install a local .deb file |
dpkg -r package | Remove a package, keep config |
dpkg -P package | Purge a package and its config |
dpkg -l | List all installed packages |
dpkg -l 'pattern*' | Filter installed packages |
dpkg -L package | List files installed by a package |
dpkg -S /path/to/file | Find which package owns a file |
dpkg -s package | Show package status and details |
dpkg --info pkg.deb | Inspect a .deb file |
dpkg --contents pkg.deb | List files in a .deb |
dpkg -x pkg.deb /dir | Extract a .deb without installing |
dpkg --get-selections | Export installed package list |
dpkg-reconfigure package | Re-run package configuration |
dpkg --configure -a | Fix 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.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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