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.debdpkg -r <package> — Remove a package (keep config files).
sudo dpkg -r nginxdpkg -P <package> — Purge a package (remove including config files).
sudo dpkg -P nginxdpkg --configure -a — Configure all unpacked but unconfigured packages.
sudo dpkg --configure -adpkg --force-depends -i <file>.deb — Force install ignoring dependency errors.
sudo dpkg --force-depends -i package.debQuery Installed Packages
dpkg -l — List all installed packages.
dpkg -ldpkg -l '<pattern>' — List packages matching a pattern.
dpkg -l 'php*'dpkg -s <package> — Show detailed status and info of a package.
dpkg -s nginxdpkg -L <package> — List all files installed by a package.
dpkg -L nginxdpkg -S <file> — Find which package owns a file.
dpkg -S /usr/sbin/nginxdpkg -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.debdpkg -c <file>.deb — List files inside a .deb file.
dpkg -c package.debdpkg -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 tzdatadpkg-reconfigure -plow <package> — Reconfigure showing all questions (even low priority).
sudo dpkg-reconfigure -plow localesdpkg --configure -a — Fix partially installed packages.
sudo dpkg --configure -aapt-get install -f — Fix broken dependencies after dpkg install.
sudo apt-get install -fCommon 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 -Pdpkg --get-selections — Export package selection state (for cloning).
dpkg --get-selections > packages.txtdpkg --set-selections < packages.txt — Import package selections (then run apt-get dselect-upgrade).
sudo dpkg --set-selections < packages.txt && sudo apt-get dselect-upgradedpkg --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
- dpkg(1) – Debian manpage – official reference for all options and actions
- dpkg – Debian Wiki – background on dpkg within the Debian package system