dpkg — quick reference
Install and remove
Work directly with .deb files and installed package names.
| When to use | Command |
|---|---|
Install a downloaded .deb package |
sudo dpkg -i package.deb |
Reinstall from a .deb file |
sudo dpkg -i --force-reinstall package.deb |
| Remove a package but keep config files | sudo dpkg -r package_name |
| Purge package and configuration files | sudo dpkg -P package_name |
| Unpack without running configure scripts | sudo dpkg --unpack package.deb |
| Configure unpacked packages | sudo dpkg --configure package_name |
| Configure every pending package | sudo dpkg --configure -a |
Query installed packages
| When to use | Command |
|---|---|
| List installed packages (optionally filter) | dpkg -l 'pattern*' |
| Show status and metadata for a package | dpkg -s package_name |
| List files installed by a package | dpkg -L package_name |
| Find which package owns a file path | dpkg -S /path/to/file |
| Audit broken or incomplete packages | sudo dpkg -C |
Inspect .deb archives
| When to use | Command |
|---|---|
Show control metadata from a .deb file |
dpkg -I package.deb |
List files inside a .deb archive |
dpkg -c package.deb |
Architecture and selections
| When to use | Command |
|---|---|
| Print native package architecture | dpkg --print-architecture |
| List enabled foreign architectures | dpkg --print-foreign-architectures |
| Export package selection states | dpkg --get-selections |
| Compare two version strings | dpkg --compare-versions 2.0 gt 1.0 |
Help and version
| When to use | Command |
|---|---|
| Show built-in usage text | dpkg --help |
| Show dpkg version | dpkg --version |
dpkg — command syntax
Synopsis from dpkg --help on Ubuntu 25.04 (dpkg 1.22.18):
Usage: dpkg [<option>...] <command>Common commands include -i|--install, -r|--remove, -P|--purge, -l|--list, -s|--status, -L|--listfiles, and -S|--search. Archive inspection uses -I and -c (implemented via dpkg-deb).
dpkg updates /var/lib/dpkg/. Install, remove, and purge need sudo.
dpkg — command examples
Essential List and inspect an installed package
Before changing packages, confirm the name, version, and state in the dpkg database.
Run the commands:
dpkg -l bash
dpkg -s bash | head -12Sample 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 bash 5.2.37-1.1ubuntu1 amd64 GNU Bourne Again SHell
Package: bash
Essential: yes
Status: install ok installed
Priority: required
Section: shells
Installed-Size: 2188
Maintainer: Ubuntu Developers <[email protected]>
Architecture: amd64
Multi-Arch: foreign
Version: 5.2.37-1.1ubuntu1The ii state means installed and configured. Essential packages like bash should not be removed.
Essential Install a local .deb file
Use dpkg -i when you already downloaded a vendor .deb. It does not fetch missing dependencies from repositories.
Build a tiny test package for this example:
mkdir -p /tmp/dpkgdemo/DEBIAN /tmp/dpkgdemo/usr/local/bin
echo '#!/bin/sh' > /tmp/dpkgdemo/usr/local/bin/dpkgdemo
echo 'echo demo' >> /tmp/dpkgdemo/usr/local/bin/dpkgdemo
chmod 755 /tmp/dpkgdemo/usr/local/bin/dpkgdemo
printf 'Package: dpkgdemo\nVersion: 1.0\nArchitecture: amd64\nMaintainer: lab\nDescription: test\n' > /tmp/dpkgdemo/DEBIAN/control
dpkg-deb --build /tmp/dpkgdemo /tmp/dpkgdemo_1.0_amd64.debInstall it:
sudo dpkg -i /tmp/dpkgdemo_1.0_amd64.debSample output:
Selecting previously unselected package dpkgdemo.
(Reading database ... 232077 files and directories currently installed.)
Preparing to unpack /tmp/dpkgdemo_1.0_amd64.deb ...
Unpacking dpkgdemo (1.0) ...
Setting up dpkgdemo (1.0) ...Verify:
dpkg -l dpkgdemoSample output:
ii dpkgdemo 1.0 amd64 testEssential Fix dependency errors after dpkg -i
When a .deb needs packages that are not installed, dpkg leaves the new package unconfigured.
If install fails with dependency errors, run:
sudo apt-get install -fThat asks apt to install missing dependencies and finish configuration. Prefer sudo apt install ./package.deb on Ubuntu 16.04+ when you want dependency resolution in one step.
Common Remove versus purge
-r removes binaries but keeps configuration under /etc. -P deletes config files too.
Remove the test package but keep configs (none for this demo):
sudo dpkg -r dpkgdemo
dpkg -l dpkgdemo 2>&1 || trueReinstall, then purge:
sudo dpkg -i /tmp/dpkgdemo_1.0_amd64.deb
sudo dpkg -P dpkgdemo
dpkg -l dpkgdemo 2>&1Sample output after purge:
dpkg-query: no packages found matching dpkgdemoUse purge when you want a clean uninstall; use remove when you might reinstall later and keep /etc settings.
Common List files and find package owners
Locate binaries from a package name, or find which package installed a path.
Run the commands:
dpkg -L bash | head -6
dpkg -S /usr/bin/bashSample output:
/.
/etc
/etc/bash.bashrc
/etc/skel
/etc/skel/.bash_logout
/etc/skel/.bashrc
bash: /usr/bin/bashOn Ubuntu, bash lives at /usr/bin/bash, not /bin/bash — adjust the path you pass to -S.
Common Read metadata from a .deb without installing
Inspect vendor packages before you install them on production.
Run the commands:
dpkg -I /tmp/dpkgdemo_1.0_amd64.deb | head -10
dpkg -c /tmp/dpkgdemo_1.0_amd64.debSample output:
new Debian package, version 2.0.
size 534 bytes: control archive=186 bytes.
109 bytes, 5 lines control
Package: dpkgdemo
Version: 1.0
Architecture: amd64
Maintainer: lab
Description: test
drwxr-xr-x root/root 0 2026-07-01 15:36 ./
drwxr-xr-x root/root 0 2026-07-01 15:36 ./usr/
drwxr-xr-x root/root 0 2026-07-01 15:36 ./usr/local/
drwxr-xr-x root/root 0 2026-07-01 15:36 ./usr/local/bin/
-rwxr-xr-x root/root 20 2026-07-01 15:36 ./usr/local/bin/dpkgdemoCommon Finish interrupted configuration with --configure -a
Power loss or a broken script can leave packages half-configured. This command runs pending configure triggers for all unpacked packages.
Run the command:
sudo dpkg --configure -aWhen nothing is pending, dpkg returns quickly with no output. Pair with sudo apt-get install -f if dependencies are still broken.
Advanced Check architecture and version compare
Pick the correct .deb arch before copying packages between hosts.
Run the commands:
dpkg --print-architecture
dpkg --print-foreign-architectures
dpkg --compare-versions 2.0 gt 1.0 && echo '2.0 is newer than 1.0'Sample output:
amd64
2.0 is newer than 1.0Foreign architectures appear only when you enabled multi-arch (for example i386 for 32-bit libraries).
Advanced Audit broken packages with -C
-C (or --audit) reports packages that are broken or need attention.
Run the command:
sudo dpkg -CEmpty output means dpkg did not find broken packages. If lines appear, read the package name and follow with sudo dpkg --configure -a and sudo apt-get install -f.
Advanced Export package selections for migration
Save which packages are installed so you can replay selections on another host (package list only — not /etc configs).
Run the command:
dpkg --get-selections | head -5Sample output:
accountsservice install
acl install
acpid install
adduser install
adwaita-icon-theme installRestore on a new machine with dpkg --set-selections < file followed by sudo apt-get dselect-upgrade — a full migration workflow, not a single dpkg flag.
dpkg — when to use / when not
| Use dpkg when | Use something else when |
|---|---|
|
dpkg vs apt
| dpkg | apt | |
|---|---|---|
| Input | .deb files and package names |
Repositories and .deb paths |
| Dependencies | Does not resolve repos | Resolves and installs deps |
| Best for | Manual .deb, queries, recovery |
Everyday installs and upgrades |
See the apt command for repository workflows.
Related commands
| Command | One line |
|---|---|
| dpkg | Low-level .deb tool (this page) |
Browse the full index in our Linux commands reference.
dpkg — interview corner
What is dpkg?
dpkg is the core Debian package tool. It installs .deb archives, removes or purges packages, configures unpacked payloads, and answers questions about what is installed on the system.
It does not download from the internet or resolve repository dependencies — that is apt's job.
A strong answer is:
"dpkg is the low-level .deb package manager on Debian and Ubuntu — install, remove, query, configure. apt sits on top and resolves dependencies from repositories."
What does dpkg --configure -a do?
It runs the configure step for every package that is unpacked but not fully configured — common after an interrupted apt upgrade or failed postinst script.
It does not magically install missing dependencies; pair it with apt-get install -f when apt reports broken deps.
A strong answer is:
"--configure -a finishes pending package configuration for all unpacked packages — I use it after interrupted installs, then apt-get install -f if dependencies are still broken."
What is the difference between dpkg -r and dpkg -P?
-r (remove) deletes program files but keeps configuration files in /etc.
-P (purge) removes the package and its config files — a clean uninstall.
A strong answer is:
"dpkg -r removes the package but keeps config; dpkg -P purges configs too. I purge when I want no trace left in /etc."
Why does dpkg fail on dependencies?
dpkg only understands the declared Depends inside the .deb you passed. If another package is missing, it stops and may leave the new package unconfigured.
Fix by installing dependencies (apt-get install -f) or using apt install ./package.deb which pulls deps from repos.
A strong answer is:
"dpkg doesn't resolve repos — missing Depends stop the install. I run apt-get install -f or apt install ./file.deb to pull dependencies."
When do you use dpkg instead of apt?
Use dpkg for direct .deb manipulation, file ownership queries (dpkg -S), listing installed files (dpkg -L), auditing broken state (dpkg -C), or automation with --get-selections.
Use apt for normal installs from configured repositories where you want dependency resolution and safer upgrades.
A strong answer is:
"apt for everyday repo installs; dpkg for inspecting local debs, querying what's installed, and recovery commands like --configure -a."
Troubleshooting
When dpkg reports a lock file, find the holding process with ps aux | grep apt; the ps command covers quick PID discovery.
| Symptom | Likely cause | Fix |
|---|---|---|
dependency problems after -i |
Missing packages | sudo apt-get install -f |
package is in a very bad inconsistent state |
Interrupted install | sudo dpkg --configure -a; then apt-get install -f |
could not open file /var/lib/dpkg/lock |
Another apt/dpkg running | Wait; ps aux | grep apt |
no path found matching pattern with -S |
Wrong path or file not from a package | dpkg -S with full path (e.g. /usr/bin/bash) |
dpkg-query: no packages found |
Package not installed or purged | dpkg -l | grep name |
Unknown option |
Flag not in your dpkg build | dpkg --help on the host |
