dpkg, handles the installation, upgrade, and removal of .deb packages on Debian‐based systems. In the early days of Linux, software was distributed as source archives (.tar.gz) requiring manual compilation. As distributions matured, package managers automated dependency resolution, file tracking, and version control. This article covers the fundamentals of using dpkg to:
- Install and upgrade packages
- Handle dependencies
- Remove or purge packages
- Force operations (with caution)
- Inspect package contents and metadata
- Reconfigure installed packages
dpkg is essential for reliable Debian system management.
1. Installing and Upgrading Packages
To install a new.deb file or upgrade an existing one:
- If no version is installed,
dpkgadds a fresh copy. - If an older version exists, it upgrades in place.
For automated dependency resolution, consider using
apt or apt-get instead.sudo apt install ./mypackage.deb will fetch missing dependencies automatically.Handling Dependency Errors
When dependencies are missing,dpkg aborts and lists unmet requirements:
.deb manually or switch to apt for automatic resolution.
2. Removing and Purging Packages
2.1 Remove (keep configuration files)
dpkg checks reverse dependencies and refuses removal if other packages rely on it:
2.2 Purge (remove package and configuration)
3. Forcing Operations
You can bypass dependency and safety checks—but this can break your system!--force-all to override nearly all safeguards. Only force when you understand the implications.
Forcing package operations may lead to an inconsistent system state. Always have backups and test in a sandbox before using on production.
4. Inspecting Packages
Here’s a quick reference for commondpkg inspection commands:
| Command | Description |
|---|---|
dpkg -I mypackage.deb | Show metadata (version, maintainer, deps) |
dpkg --get-selections | List all installed packages |
dpkg -L unrar | List files installed by a package |
dpkg-query -S /usr/bin/unrar* | Find which package owns a given file |
4.1 View Package Metadata
4.2 List Files in a Package
4.3 Identify Owning Package of a File
5. Reconfiguring Packages
Sometimes you need to rerun a package’s configuration scripts—useful after restoring defaults or changingdebconf answers: