LinuxCommandLibrary

dpkg

Install, remove, and manage Debian packages

TLDR

Install a package

$ dpkg [[-i|--install]] [path/to/file.deb]
copy

Remove a package
$ dpkg [[-r|--remove]] [package]
copy

List installed packages
$ dpkg [[-l|--list]] [pattern]
copy

List a package's contents
$ dpkg [[-L|--listfiles]] [package]
copy

List contents of a local package file
$ dpkg [[-c|--contents]] [path/to/file.deb]
copy

Find out which package owns a file
$ dpkg [[-S|--search]] [path/to/file]
copy

Purge an installed or already removed package, including configuration
$ dpkg [[-P|--purge]] [package]
copy

SYNOPSIS

dpkg [option...] command
dpkg {-S | -L | -l | -s | -c | -I | --field | --compare-versions} [package_name | file_path | .deb_file]

PARAMETERS

-i, --install
    Install a .deb package archive.

-r, --remove
    Remove an installed package, leaving configuration files behind.

-P, --purge
    Remove an installed package completely, including configuration files.

-l, --list
    List all installed packages with their status.

-s, --status
    Display detailed status information for an installed package.

-L, --listfiles
    List all files installed by a given package.

-S, --search
    Search for packages that own a specific file.

--configure
    Configure an unpacked but unconfigured package.

-I, --info
    Show information from a .deb package archive.

-c, --contents
    List the contents (files) of a .deb package archive.

--get-selections
    Get list of package selections for dpkg.

--set-selections
    Set package selections from a file or standard input.

--audit
    Check for broken packages on the system.

DESCRIPTION

dpkg is the fundamental package management system for Debian-based Linux distributions, including Ubuntu and Linux Mint. It operates at a low level, directly handling the installation, removal, and querying of individual .deb package files. Unlike higher-level tools such as apt or apt-get, dpkg does not automatically resolve or manage package dependencies. This means that if a package you're installing with dpkg requires other packages, you must install those dependencies manually beforehand. This characteristic makes dpkg a powerful but potentially challenging tool if used without care, especially for systems with complex dependency trees.

While apt is generally preferred for everyday package management due to its dependency resolution capabilities, dpkg remains essential for scenarios like installing a locally downloaded .deb file, querying detailed information about installed packages, or troubleshooting package issues. It provides the core mechanisms upon which higher-level tools are built, making it indispensable for understanding the Debian package ecosystem.

CAVEATS

dpkg does not automatically handle package dependencies. Installing a package with dpkg -i that has unmet dependencies will result in a broken package state, requiring manual resolution, often with apt --fix-broken install. Using dpkg directly for significant system changes without understanding dependencies can lead to an unstable system. Most operations require root privileges.

<B>PACKAGE STATES</B>

When listing packages with dpkg -l or checking status with dpkg -s, you'll encounter various two-letter codes indicating the package's desired and current state. Common states include:
ii: (install ok installed) - package is successfully installed.
rc: (remove ok config-files) - package has been removed, but configuration files remain.
pn: (purge not-installed) - package has been purged, it's not installed, and no config files remain.
ri: (remove installed) - package marked for removal, but still installed (broken state).
un: (unknown not-installed) - package is not installed and its status is unknown.

<B>LOCAL .DEB INSTALLATION</B>

dpkg -i /path/to/package.deb is the command to install a package downloaded from outside official repositories. Remember to resolve any dependencies manually or use sudo apt --fix-broken install afterwards if dependencies are missing.

HISTORY

dpkg is the original package management system for Debian GNU/Linux, developed shortly after the project's inception in the early 1990s. It was designed to manage individual .deb packages. Its core functionality provided the foundation for Debian's robust software ecosystem. The apt (Advanced Package Tool) suite was later developed and introduced to address dpkg's limitation regarding automatic dependency resolution, making package management much more user-friendly and efficient for complex systems. Despite apt's widespread use, dpkg remains the underlying engine, essential for low-level package operations and system integrity checks.

SEE ALSO

apt(8), apt-get(8), dpkg-reconfigure(8), dpkg-deb(1), dpkg-query(1), deb(5), dselect(8)

Copied to clipboard