Quick take: Use sudo dpkg -i package.deb to install a local .deb file, dpkg -l to list installed packages, and dpkg -S /path/to/file to find which package owns a file. Run sudo apt -f install afterward to fix dependencies.
Introduction
The dpkg command is the low-level package tool underneath apt on Debian and Ubuntu. While apt fetches packages from repositories and resolves dependencies, dpkg works directly with individual .deb files and the local package database — useful for installing a downloaded package or querying what is installed.
This guide covers installing and removing local packages, listing and inspecting installed software, and finding which package a file belongs to.
Syntax
The basic syntax of the dpkg command is:
dpkg [OPTIONS] [PACKAGE|FILE]Common Options and Parameters
The most useful options and parameters for the dpkg command:
| Option | Description |
|---|---|
| -i FILE | Install a local .deb package. |
| -r PKG | Remove a package (keep config files). |
| -P PKG | Purge a package (remove config files too). |
| -l [PAT] | List installed packages (optionally matching a pattern). |
| -L PKG | List the files installed by a package. |
| -S FILE | Find which package owns a file. |
| -s PKG | Show the status and details of a package. |
| --configure -a | Configure any unpacked-but-unconfigured packages. |
Practical Examples
Real dpkg commands you can run today:
# Install a downloaded .deb file
sudo dpkg -i ./app_1.2.3_amd64.deb
# Fix missing dependencies after a dpkg install
sudo apt -f install
# List installed packages matching a name
dpkg -l | grep nginx
# List files a package installed
dpkg -L nginx
# Find which package owns a file
dpkg -S /usr/bin/curl
# Remove a package
sudo dpkg -r appnameTips and Best Practices
- dpkg does not resolve dependencies. After
dpkg -ireports missing ones, runsudo apt -f installto pull them in. dpkg -S /pathanswers “which package installed this file?” — invaluable when troubleshooting.- Prefer
apt install ./file.debon modern systems; it installs a local .deb and resolves dependencies automatically.
Final Thoughts
dpkg is the direct, low-level way to install and inspect .deb packages on Debian-based systems. Use it to install a downloaded package, list what a package contains, or trace a file back to its package — and remember it does not handle dependencies, so follow up with apt -f install. For everyday installs, apt remains the friendlier choice.
FAQ: dpkg Command in Linux
How do I install a .deb file in Linux?+
Use sudo dpkg -i package.deb. If it reports missing dependencies, run sudo apt -f install to resolve them. On modern systems you can also use sudo apt install ./package.deb, which handles dependencies directly.
How do I list all installed packages?+
Use dpkg -l to list every installed package, or dpkg -l | grep name to filter for a specific one. apt list --installed gives a similar view.
How do I find which package a file belongs to?+
Use dpkg -S /path/to/file, for example dpkg -S /usr/bin/curl, which reports the owning package.
What is the difference between dpkg and apt?+
dpkg is the low-level tool that works with individual .deb files and does not fetch from repositories or resolve dependencies. apt is the high-level manager that downloads packages and handles dependencies for you.
How do I see what files a package installed?+
Use dpkg -L packagename to list every file the package placed on the system, which is useful for locating its binaries and configuration.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support