dpkg Cheatsheet
Quick reference for installing, removing, querying, and inspecting Debian packages with dpkg
dpkg is the low-level package manager used by Debian, Ubuntu, and related distributions. This cheatsheet covers common dpkg commands for local .deb files, installed package queries, package selections, and repair tasks.
Install and Remove
Work with installed packages and local .deb files.
| Command | Description |
|---|---|
sudo dpkg -i package.deb | Install a local .deb file |
sudo dpkg -i *.deb | Install multiple .deb files |
sudo dpkg -r package | Remove package, keep config |
sudo dpkg -P package | Purge package and config |
sudo dpkg --unpack package.deb | Unpack without configuring |
Query Installed Packages
List packages and inspect installed package metadata.
| Command | Description |
|---|---|
dpkg -l | List installed packages |
dpkg -l 'nginx*' | Filter packages by pattern |
dpkg -s package | Show package status |
dpkg --status package | Same as dpkg -s |
dpkg-query -W package | Show package and version |
Package Files
Find installed files and file ownership.
| Command | Description |
|---|---|
dpkg -L package | List files installed by package |
dpkg -S /path/to/file | Find package owning a file |
dpkg -S '*/bin/curl' | Search ownership by pattern |
dpkg -L package | less | Browse long file lists |
dpkg -V package | Verify installed package files |
Inspect deb Files
Read package archives before installing them.
| Command | Description |
|---|---|
dpkg --info package.deb | Show .deb metadata |
dpkg -I package.deb | Same as dpkg --info |
dpkg --contents package.deb | List files in .deb |
dpkg -c package.deb | Same as dpkg --contents |
dpkg-deb -f package.deb Version | Print package version field |
Extract deb Files
Unpack archive contents without installing.
| Command | Description |
|---|---|
dpkg -x package.deb /tmp/extract | Extract package files |
dpkg -X package.deb /tmp/extract | Extract with details |
dpkg -e package.deb /tmp/control | Extract control files |
dpkg-deb --ctrl-tarfile package.deb | Print control tar archive |
dpkg-deb --fsys-tarfile package.deb | Print filesystem tar archive |
Package Selections
Export and restore package selection states.
| Command | Description |
|---|---|
dpkg --get-selections | Print package selections |
dpkg --get-selections > packages.txt | Save selections |
sudo dpkg --set-selections < packages.txt | Restore selections |
dpkg --get-selections 'nginx*' | Filter selections |
sudo apt-get dselect-upgrade | Apply restored selections |
Repair and Configure
Resume interrupted installs and fix package state.
| Command | Description |
|---|---|
sudo dpkg --configure -a | Configure pending packages |
sudo dpkg --configure package | Configure one package |
sudo dpkg -C | Audit broken packages |
sudo apt install -f | Fix missing dependencies |
sudo dpkg-reconfigure package | Re-run package setup |
Related Guides
Use these references for package management workflows.
| Guide | Description |
|---|---|
dpkg Command in Linux | Full dpkg tutorial with examples |
Install deb Files on Ubuntu | Install local .deb files with apt and dpkg |
apt Cheatsheet | Higher-level package management commands |