dpkg — The Low-Level Debian Package Tool

Practical guide to dpkg: install local .deb packages, query package status and contents, and repair installations — the foundation beneath apt.

dpkg is Debian's low-level package tool and the foundation that apt and apt-get are built on. You use it to install local .deb files directly, query the status of installed packages, list their contents, or find out which package a given file belongs to. Unlike apt, however, dpkg does not resolve dependencies – it processes exactly the packages you hand it. This guide walks you through the essential dpkg commands for installing, querying and repairing packages.

Install & Remove

dpkg -i <file>.deb — Install a .deb package.

sudo dpkg -i package.deb

dpkg -r <package> — Remove a package (keep config files).

sudo dpkg -r nginx

dpkg -P <package> — Purge a package (remove including config files).

sudo dpkg -P nginx

dpkg --configure -a — Configure all unpacked but unconfigured packages.

sudo dpkg --configure -a

dpkg --force-depends -i <file>.deb — Force install ignoring dependency errors.

sudo dpkg --force-depends -i package.deb

Query Installed Packages

dpkg -l — List all installed packages.

dpkg -l

dpkg -l '<pattern>' — List packages matching a pattern.

dpkg -l 'php*'

dpkg -s <package> — Show detailed status and info of a package.

dpkg -s nginx

dpkg -L <package> — List all files installed by a package.

dpkg -L nginx

dpkg -S <file> — Find which package owns a file.

dpkg -S /usr/sbin/nginx

dpkg -S '<pattern>' — Search for packages by file path pattern.

dpkg -S '*/bin/python*'

Query .deb Files

dpkg -I <file>.deb — Show info about a .deb file (before installing).

dpkg -I package.deb

dpkg -c <file>.deb — List files inside a .deb file.

dpkg -c package.deb

dpkg -x <file>.deb <dir> — Extract files from a .deb to a directory.

dpkg -x package.deb /tmp/extract/

dpkg -e <file>.deb <dir> — Extract control info from a .deb file.

dpkg -e package.deb /tmp/control/

Reconfigure & Repair

dpkg-reconfigure <package> — Reconfigure an installed package (re-run setup).

sudo dpkg-reconfigure tzdata

dpkg-reconfigure -plow <package> — Reconfigure showing all questions (even low priority).

sudo dpkg-reconfigure -plow locales

dpkg --configure -a — Fix partially installed packages.

sudo dpkg --configure -a

apt-get install -f — Fix broken dependencies after dpkg install.

sudo apt-get install -f

Common Patterns

dpkg -l | grep '^ii' — List only properly installed packages.

dpkg -l | grep '^ii'

dpkg -l | grep '^rc' — List removed packages with leftover config files.

dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo dpkg -P

dpkg --get-selections — Export package selection state (for cloning).

dpkg --get-selections > packages.txt

dpkg --set-selections < packages.txt — Import package selections (then run apt-get dselect-upgrade).

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

dpkg --compare-versions <v1> <op> <v2> — Compare package version numbers.

dpkg --compare-versions 2.0 gt 1.5 && echo 'newer'

Conclusion

dpkg is the bedrock of Debian package management: precise, fast and indispensable when you need to install a single .deb file or find out exactly which package ships a given file. The crucial catch: dpkg resolves no dependencies – a dpkg -i can leave your system in an inconsistent state that you then repair with sudo apt-get -f install. The -r, -P and --purge options remove packages (and, with -P/--purge, their configuration too) without asking, so double-check the package name. For everyday work – installing and upgrading packages from repositories – reach for apt instead; dpkg is the tool for local files, queries and emergency repairs.

Further Reading

  • apk – package manager for Alpine Linux
  • apt – convenient high-level front-end for Debian package management
  • apt-get – classic, script-friendly APT tool