Mastering Package Management system with Dpkg

Dpkg is a low-level package management tool for Debian-based Linux systems. It provides direct control over package installation, removal, configuration, and querying through command-line parameters. Unlike higher-level tools like apt, dpkg operates directly on .deb package files and maintains the package database.

Every dpkg command consists of one action parameter that tells dpkg what to do, along with optional flags that modify the behavior. Dpkg is the foundation upon which other package managers are built.

Getting Help

To view all available dpkg options and commands −

dpkg --help

This displays a comprehensive list of commands including installation, removal, configuration, and query operations.

Package Installation

To install a .deb package file −

sudo dpkg -i package_name.deb

To install all packages from a directory recursively −

sudo dpkg -R -i /path/to/directory/

Package Removal

Remove Package (Keep Configuration Files)

sudo dpkg -r package_name

Purge Package (Remove Everything)

sudo dpkg -P package_name

Purging removes the package and all its configuration files, while removal keeps configuration files for potential reinstallation.

Package Information and Status

Check Package Status

dpkg -s package_name

Display Available Package Information

dpkg -p package_name

List All Installed Packages

dpkg -l
ii  firefox        91.0+build2-0ubuntu1    amd64        Safe and easy web browser
ii  gcc            4:9.3.0-1ubuntu2        amd64        GNU C compiler
ii  git            1:2.25.1-1ubuntu3       amd64        fast, scalable, distributed revision control
rc  vlc            3.0.9.2-1               amd64        multimedia player and streamer

The status codes indicate: ii = installed, rc = removed but config files remain, un = unknown.

Package Configuration and Maintenance

Configure Package

sudo dpkg --configure package_name

Configure All Pending Packages

sudo dpkg --configure -a

Verify Package Integrity

dpkg -V package_name

Advanced Operations

List Package Files

dpkg -L package_name

Find Package Owning a File

dpkg -S /path/to/file

Unpack Without Installing

sudo dpkg --unpack package_name.deb

System Information

Display System Architecture

dpkg --print-architecture
amd64

Clear Package Selections

sudo dpkg --clear-selections

Common Use Cases

Task Command Purpose
Install local package dpkg -i package.deb Install downloaded .deb file
Fix broken dependencies dpkg --configure -a Complete interrupted installations
List package contents dpkg -L package See what files a package installed
Find file owner dpkg -S filename Identify which package owns a file

Conclusion

Dpkg is the fundamental package management tool for Debian systems, providing direct control over package operations. While higher-level tools like apt are more convenient for daily use, dpkg is essential for low-level package management, troubleshooting, and handling local .deb files. Understanding dpkg commands helps system administrators maintain precise control over their package installations.

Updated on: 2026-03-17T09:01:38+05:30

327 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements