✦ For everyone, free.

Practical knowledge for real and everyday life

Home

dpkg

dpkg is a package manager for Debian-based systems, handling installation, removal, and management of software packages through .deb files.

dpkg is the low-level package manager for Debian-based Linux distributions, responsible for installing, removing, configuring, and managing .deb software packages. It operates directly on the Debian package database and provides essential tools to manipulate individual package files without dependency resolution, which higher-level package managers like APT utilize for more complex package management tasks.


Overview of dpkg

dpkg handles software packages in the Debian format (.deb), which are archives containing executable files, configuration files, metadata, and control scripts. The core function of dpkg is to unpack these files into the system, manage package metadata, and maintain the internal database reflecting the installed state of packages.

Unlike APT or aptitude, dpkg does not automatically resolve dependencies or download packages from repositories. Its primary role is to execute package operations requested by the user or by package management frontends.


dpkg Package Database and States

Package Database Location

dpkg maintains its internal database primarily in /var/lib/dpkg/, which includes several important files:

  • status: Contains the current status and details of all installed packages.
  • available: Lists packages known to the system, often updated by APT.
  • diversions: Tracks files that have been diverted from their original packages.
  • info/: A directory containing package-specific metadata and control files such as configuration scripts and file lists.

Package States

Each package tracked by dpkg can be in multiple states, describing whether it is installed, unpacked, configured, or removed but with residual configuration files left behind. Key states include:

  • Not installed: The package is not present on the system.
  • Unpacked: Files have been extracted but not yet configured.
  • Half-configured: Configuration has started but not completed.
  • Installed: Package is fully installed and configured.
  • Config-files: Package is removed but some configuration files remain.
  • Half-installed: Installation failed partway.
  • Triggers-awaited/Triggers-pending: Related to deferred package trigger processing.

These states allow dpkg to manage complex installation and removal workflows robustly.


dpkg Selections

dpkg maintains a list of package selections, which represent the desired state of packages as recorded by the user or system. These selections can be manipulated using dpkg --set-selections and queried with dpkg --get-selections.

Common selection states include:

  • install: Mark package for installation.
  • hold: Prevent package from being automatically installed, upgraded, or removed.
  • deinstall: Mark package for removal but retain configuration files.
  • purge: Mark package for complete removal including config files.

Managing selections is important for batch operations and automated package management.


dpkg Package Operations

Installing and Upgrading Packages

The primary command to install or upgrade a package from a .deb file is:

dpkg -i package_file.deb

This command unpacks the package and runs its configuration scripts. If dependencies are missing, dpkg will report errors but will not resolve them automatically.

Removing Packages

To remove a package but keep its configuration files:

dpkg -r package_name

To completely remove a package including its configuration files:

dpkg -P package_name

Querying Packages

dpkg provides rich querying capabilities:

  • List all installed packages:
dpkg -l
  • Show detailed information about a package:
dpkg -s package_name
  • List files installed by a package:
dpkg -L package_name
  • Find which package owns a file:
dpkg -S /path/to/file

Configuration and Triggers

After unpacking, dpkg runs package maintainer scripts such as postinst to configure the package. It also processes triggers, which allow deferred actions to run after multiple package operations, improving efficiency and consistency.


Interaction with Higher-Level Tools

While dpkg manages packages at the granular level, it does not handle dependency resolution or package acquisition from remote repositories. Higher-level tools like APT or aptitude use dpkg internally to perform the actual package installation and removal after resolving dependencies and downloading necessary packages.

This separation allows dpkg to be simple, robust, and powerful for direct package manipulation, while higher-level tools provide user-friendly interfaces and advanced features.


Summary

  • dpkg is the foundational Debian package management tool working with .deb files.
  • It manages a detailed package database with multiple package states to track installation progress.
  • It allows fine-grained control over package installation, removal, configuration, and querying.
  • It operates without automatic dependency resolution, delegating this task to frontends like APT.
  • dpkg maintains package selections for batch operations and supports triggers for deferred actions.

dpkg is essential for system administrators and automation scripts requiring precise control over Debian package management.