Linux

dpkg: Complete Guide to Package Management in Ubuntu/Debian

This guide explains how to use the standard dpkg utility for basic package operations in Debian-based distributions. You'll learn to install, remove, query packages, and solve common issues.

Updated at February 16, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Debian 12/11Ubuntu 22.04/24.04Linux Mint 21/22

Introduction / Why You Need This

dpkg is a low-level package manager that forms the foundation of package management systems in Debian-based distributions (Debian, Ubuntu, Linux Mint, etc.). While apt and apt-get are convenient for working with repositories, dpkg is indispensable for manually installing local .deb files, inspecting package states in detail, and resolving complex dependency issues. This guide covers the essential operations every Linux administrator or advanced user will need.

Requirements / Preparation

  1. Debian-based distribution: These instructions are current for Debian, Ubuntu, Linux Mint, and their derivatives.
  2. Superuser privileges: Most operations (-i, -r, -P) require sudo.
  3. Local .deb file: For the installation step, you will need a downloaded package file (e.g., from the project's official website).
  4. Basic terminal familiarity: Ability to navigate (cd, ls) and edit commands.

Step 1: Check dpkg Presence and Version

Although dpkg is almost always pre-installed, it's useful to verify its presence and check the version.

dpkg --version

Expected output (example):

Debian `dpkg` package management program version 1.22.0 (amd64).

If the command is not found, install the dpkg package using your distribution's package manager (e.g., sudo apt update && sudo apt install dpkg).

Step 2: Install a Package from a Local .deb File

This is the primary operation for installing software not available in official repositories or for installing a specific version.

  1. Navigate to the directory containing the downloaded file (e.g., ~/Downloads).
  2. Perform the installation:
sudo dpkg -i package_file.deb
  • -i (install) — the key flag.
  • Important: dpkg does not automatically resolve dependencies. If the package requires other libraries or programs, the installation will fail with an error. In this case, proceed to Step 6 to fix it.

Example:

cd ~/Downloads
sudo dpkg -i google-chrome-stable_current_amd64.deb

Step 3: Remove a Package

Removal via dpkg is more "raw" than via apt, but it gives you precise control.

  • Remove package (keeps configs):
    sudo dpkg -r package_name
    
    • -r (remove) — removes the package's binaries and data but preserves configuration files in /etc/. This is useful if you plan to reinstall the package with the same settings.
  • Purge package (removes configs):
    sudo dpkg -P package_name
    
    • -P (purge) — removes everything, including configurations. Use with caution; settings will be lost permanently.

Example:

sudo dpkg -r nginx
# or
sudo dpkg -P nginx

Step 4: View Information About Installed Packages

dpkg provides several ways to get information.

  • List all installed packages:
    dpkg -l
    

    The output is very long. Use grep to filter:
    dpkg -l | grep -i python
    
  • Detailed information about a specific package:
    dpkg -s package_name
    

    Shows status, version, description, dependencies, sizes, and other metadata.
  • List files installed by a package:
    dpkg -L package_name
    

    Useful to understand exactly where a package "installed itself".
  • Search for a package by file:
    dpkg -S /path/to/file
    

    Answers the question "Which package owns this file?".

Example:

dpkg -s curl
dpkg -S /usr/bin/curl

Step 5: Verify Package Integrity

If you suspect system files have been altered (e.g., after a hack or crash), you can verify if they match the package database.

sudo dpkg -V package_name
  • Without a package name, it will verify all installed packages (this can take a long time).
  • In the output, characters in the first 5 columns indicate changes (e.g., 5 = checksum change, M = permission mode change). Empty columns mean the file is unchanged.

Step 6: Resolving Dependency Problems (Common Case)

The most common error when using dpkg -i:

dpkg: dependency problems prevent configuration of package_name

This means the package requires other packages that are not yet installed.

Solution: Use apt, which can automatically find and install missing dependencies from repositories.

sudo apt --fix-broken install

This command will analyze broken dependencies and install the missing packages. After it completes successfully, you can try sudo dpkg -i package_file.deb again, or simply proceed—apt often configures the package automatically after fixing dependencies.

Force reconfiguration: If a package is installed but not configured (status rc), run:

sudo dpkg --configure -a

Step 7: Working with Packages in "Read-Only" Mode (extract)

Sometimes you just need to extract files from a .deb archive without installing them to the system (e.g., to view scripts).

  1. Create a temporary directory.
  2. Unpack the ar archive (the .deb format is an ar archive):
    mk temp_dir && cd temp_dir
    ar xx /path/to/package.deb
    
  3. Extract the contents of data.tar.xz (or data.tar.gz):
    tar -xf data.tar.xz
    

Now all the package's files will be in the current directory.

Verifying the Result

After performing the main operations, check the outcome:

  • After installation: dpkg -l | grep package_name (status should be ii).
  • After removal: dpkg -l | grep package_name (status should be rc or the package should not appear).
  • After fixing dependencies: Ensure the sudo apt --fix-broken install command completed without errors.
  • Check program functionality: Run it (e.g., nginx -v or google-chrome --version).

Possible Issues

  • Error "dpkg: error: parsing file '/var/lib/dpkg/status' near line X..."
    • Cause: Corrupted package database.
    • Solution: Restore from backup: sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status. If no backup exists, try creating an empty file: echo "Package: status\ndpkg" | sudo tee /var/lib/dpkg/status (caution: this resets installation history).
  • "dpkg: warning: package not marked as conffile, but configuration file found: ..."
    • Cause: A configuration file (conffile) was manually modified, and the package is trying to overwrite it.
    • Solution: Either save your version of the file, or allow dpkg to install the version from the package (during an upgrade). Use dpkg-divert if you need to preserve a custom file.
  • Package "stuck" in "half-installed" or "half-configured" state
    • Solution: Force remove the problematic package: sudo dpkg --remove --force-remove-reinstreq package_name, then clean up dependencies with sudo apt --fix-broken install.
  • No permissions for file in installation directory
    • Cause: Attempting to install a package to a system directory without sudo.
    • Solution: Always use sudo for write operations (-i, -r, -P).

Additional Features (Briefly)

  • dpkg-reconfigure package_name — re-runs the package's configuration script (useful after changing a config or on configuration errors).
  • dpkg --get-selections — outputs a list of all packages with their status (install, hold, deinstall). Can be saved to a file for backup.
  • dpkg --set-selections < file — restores package selections from a file created by --get-selections.
  • dpkg -C — verifies the filesystem integrity of packages, looking for missing or corrupted files.

Conclusion

You have mastered a basic but critically important tool—dpkg. Remember: for everyday work with repositories, use apt. Reserve dpkg for manually installing .deb files, detailed auditing, and solving complex package problems. Always check dependencies after a manual install with sudo apt --fix-broken install.

F.A.Q.

What's the difference between dpkg and apt?
{ "How to fix the error 'dpkg": { "error processing package ": [ [ { " (--configure)": "dependency problems prevent configuration'?" } ] ] } }
Can dpkg be used to remove a package's configuration files?
How to find out which package installed a specific file?

Hints

Check if dpkg is installed
Install a package from a .deb file
Remove a package
Get information about installed packages
Find which package owns a file
Verify package integrity
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community