Skip to main content
Debian’s native package manager, 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
Whether you’re a sysadmin automating deployments or a developer packaging your own software, understanding 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, dpkg adds 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:
Sample output:
You must install each required .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:
To remove multiple packages at once:

2.2 Purge (remove package and configuration)

Purging deletes all configuration files, freeing up disk space and resetting system state.

3. Forcing Operations

You can bypass dependency and safety checks—but this can break your system!
Use --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 common dpkg inspection commands:

4.1 View Package Metadata

4.2 List Files in a Package

Sample output:

4.3 Identify Owning Package of a File

Output:

5. Reconfiguring Packages

Sometimes you need to rerun a package’s configuration scripts—useful after restoring defaults or changing debconf answers:
This command re-executes maintainer scripts, prompting you to confirm or update settings as needed.

References

Future installments will cover advanced package building, repository management, and best practices for Debian package maintenance.

Watch Video