dpkg Command in Linux With Examples

dpkg is a low-level package management system for Debian-based Linux distributions like Ubuntu, Debian, and Linux Mint. It handles the installation, removal, and management of .deb package files directly. While higher-level tools like apt and apt-get provide dependency resolution, dpkg focuses on the core operations of package handling.

What is the dpkg Command?

The dpkg command is responsible for the fundamental package management tasks such as unpacking archives, installing files, configuring packages, and maintaining the package database. It operates at a lower level than tools like apt, giving administrators direct control over individual package operations without automatic dependency handling.

Basic Syntax

The basic syntax of the dpkg command is

dpkg [options] <action> <package_name>

Where

  • options Optional flags to modify command behavior

  • action The operation to perform (install, remove, list, etc.)

  • package_name The target package name or .deb file

Common dpkg Options

Option Action Description
-i Install Install a .deb package file
-r Remove Remove package (keep config files)
-P Purge Remove package and config files
-l List List installed packages
-s Status Show package information
-S Search Find package owning a file
-L Listfiles List files installed by package

Examples

Installing a Package

To install a local .deb package file

sudo dpkg -i firefox.deb

Removing a Package

To remove a package while keeping configuration files

sudo dpkg -r firefox

Purging a Package

To completely remove a package and its configuration files

sudo dpkg -P firefox

Listing Installed Packages

To view all installed packages

dpkg -l

To search for a specific package

dpkg -l | grep firefox

Package Information

To display detailed information about an installed package

dpkg -s firefox

Finding Package by File

To determine which package owns a specific file

dpkg -S /usr/bin/firefox

Listing Package Files

To see all files installed by a package

dpkg -L firefox

Package Verification

To verify package integrity and check for modified files

sudo dpkg -V firefox

Reconfiguring a Package

To run a package's configuration script again

sudo dpkg --configure firefox

Key Points

  • No dependency resolution dpkg does not automatically handle dependencies like apt does

  • Direct package manipulation Works directly with .deb files and installed packages

  • Database maintenance Maintains the package database in /var/lib/dpkg/

  • Root privileges required Most dpkg operations require sudo or root access

Conclusion

The dpkg command provides essential low-level package management capabilities for Debian-based systems. While it lacks automatic dependency resolution, it offers precise control over individual package operations. Understanding dpkg is crucial for system administrators who need direct package manipulation capabilities beyond what higher-level tools provide.

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

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements