Website Vidya
Linux & ServersStep-by-Step Guide

How to Use dpkg Command to Install and Manage Debian Packages

Learn how to use dpkg command to install and manage debian packages in Ubuntu 24.04, resolve dependency errors, inspect package contents, and purge files.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Use dpkg Command to Install and Manage Debian Packages
AI Executive SummaryWebsiteVidya AI

6 min read

Learn how to use dpkg command to install and manage debian packages in Ubuntu 24.04, resolve dependency errors, inspect package contents, and purge files.

Key Highlights
  • Prerequisites and Supported Releases
  • Understanding the Relationship Between dpkg and apt
  • Step 1: Installing a Local .deb Package with dpkg -i
Grounded in full engineering runbookWebsiteVidya AI Engine

Every software package installed on an Ubuntu system—from the Linux kernel and systemd daemons to web servers and developer runtimes—is distributed as a Debian package archive (.deb).

While higher-level utilities like apt and apt-get automatically locate, download, and resolve dependencies from remote internet repositories, the low-level engine that actually unpacks, configures, and tracks files on disk is dpkg (Debian Package).

Whenever you download proprietary drivers, standalone developer tools (such as Google Chrome, VS Code, or custom internal builds) as .deb files, dpkg is the primary tool used for installation.

However, because dpkg does not resolve dependencies automatically, using it effectively requires understanding how to pair it with APT's dependency resolution tools.

Advertisement

In this tutorial, we demonstrate how to use dpkg command to install and manage debian packages, inspect package metadata, fix dependency errors, and remove software cleanly.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

Advertisement
  • A server or computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A non-root user account with sudo administrative privileges.
  • Access to a bash terminal shell.
  • A local .deb package file for installation testing.

Understanding the Relationship Between dpkg and apt

Understanding Linux package management requires distinguishing between the low-level package manager (dpkg) and the high-level repository frontend (apt):

Review this architectural division of responsibilities:

Attribute / Featuredpkg (Low-Level Engine)apt (High-Level Frontend)
Primary RoleInstalls, unpacks, and queries local .deb files directly on diskDownloads packages from remote internet repositories and calculates dependency trees
Dependency ResolutionNone (Fails if required prerequisite packages are missing)Automatic (Recursively downloads and installs all prerequisite dependencies)
Target OperandAccepts local file paths (e.g. dpkg -i package.deb)Accepts package names (e.g. apt install nginx)
Database MaintenanceMaintains local package database in /var/lib/dpkg/statusMaintains repository caches in /var/lib/apt/lists/

Step 1: Installing a Local .deb Package with dpkg -i

To install a downloaded Debian package file, use the -i (install) flag with sudo privilege.

Download a sample package using wget or reference an existing .deb file on your system:

Advertisement

Execute the installation command:

# Download a sample Debian package (e.g. fastfetch):
wget https://github.com/fastfetch-cli/fastfetch/releases/download/2.15.0/fastfetch-linux-amd64.deb

# Install the package using dpkg:
sudo dpkg -i fastfetch-linux-amd64.deb
# Output:
# Selecting previously unselected package fastfetch.
# (Reading database ... 185420 files and directories currently installed.)
# Preparing to unpack fastfetch-linux-amd64.deb ...
# Unpacking fastfetch (2.15.0) ...
# Setting up fastfetch (2.15.0) ...
# Processing triggers for man-db (2.12.0-4build2) ...

# Verify installed binary:
fastfetch --version

Step 2: Resolving Missing Dependency Errors with apt --fix-broken

Because dpkg does not download dependencies from the internet, attempting to install a package that requires uninstalled system libraries triggers a dependency failure.

When this occurs, dpkg leaves the package in an unconfigured state and exits with an error:

To automatically download and install the missing dependencies from Ubuntu's repositories, invoke APT's broken dependency repair command:

# Example dependency error during dpkg -i:
# dpkg: dependency problems prevent configuration of package-name:
#  package-name depends on libssl3 (>= 3.0.0); however:
#   Package libssl3 is not installed.
# dpkg: error processing package package-name (--install)

# Resolve and install all missing dependencies automatically:
sudo apt --fix-broken install -y

# Output confirms:
# Correcting dependencies... Done
# The following additional packages will be installed: libssl3
# Setting up package-name ... Done.

Step 3: Listing and Querying Installed Packages with dpkg -l

The dpkg -l command lists all software packages installed on your Ubuntu system.

Pipe the output to grep or less to search for specific packages:

The leading two characters of each output line represent the desired package status and active state (e.g., ii signifies 'installed and configured'):

# List all installed packages matching 'nginx':
dpkg -l | grep nginx
# Output:
# ii  nginx          1.24.0-2ubuntu7  amd64  small, powerful, scalable web/proxy server
# ii  nginx-common   1.24.0-2ubuntu7  all    small, powerful, scalable web/proxy server - common files

# Inspect detailed package metadata and architecture:
dpkg -s nginx
# Displays Version, Maintainer, Depends, Architecture, and Description.

Step 4: Inspecting Package Files with dpkg -L and dpkg -S

Two of the most useful diagnostic flags in dpkg allow you to cross-reference files on your filesystem with their parent package.

Use dpkg -L to list every single file and directory installed by a package:

Conversely, use dpkg -S to identify which package owns an arbitrary binary or configuration file on disk:

# List all files installed by 'nginx':
dpkg -L nginx
# Output:
# /etc/nginx
# /etc/nginx/nginx.conf
# /usr/sbin/nginx
# /usr/share/man/man8/nginx.8.gz

# Discover which package installed /usr/bin/curl:
dpkg -S /usr/bin/curl
# Output: curl: /usr/bin/curl

Step 5: Removing and Purging Packages with dpkg -r and dpkg -P

When uninstalling software via dpkg, distinguish between removing and purging:

Review the behavior of removal directives:

# Remove package binaries while preserving configurations:
sudo dpkg -r fastfetch

# Completely purge package and all configuration files:
sudo dpkg -P fastfetch
# Output:
# Removing fastfetch (2.15.0) ...
# Purging configuration files for fastfetch (2.15.0) ...
CommandAction PerformedConfiguration Files Retained?
sudo dpkg -r packageRemoves binary executables, libraries, and man pagesYes (Keeps custom configuration files in /etc/)
sudo dpkg -P packageCompletely purges all binaries, libraries, and configuration filesNo (Wipes all configuration files completely)

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

dpkg: error: dpkg frontend lock was impossible to get

Cause: Another process (such as unattended-upgrades or an active apt command) is holding /var/lib/dpkg/lock-frontend.

Resolution: Check active processes with ps aux | grep -i apt or wait for background unattended upgrades to finish.

sudo fuser -v /var/lib/dpkg/lock-frontend

dpkg: error processing package (--install): cannot access archive: No such file or directory

Cause: Typographical error in filename or command was executed in the wrong directory.

Resolution: Verify file existence with ls -la *.deb or supply the absolute file path.

ls -la *.deb

Package is in a very bad inconsistent state; reinstall it before attempting to remove it

Cause: Installation was interrupted during the post-installation script execution.

Resolution: Reconfigure pending packages with sudo dpkg --configure -a or force re-installation.

sudo dpkg --configure -a

Security Best Practices and Hardening

Only install .deb packages obtained from trusted upstream developers; deb packages execute pre/post installation scripts with full root privileges.

Inspect the pre-installation scripts and contents of an untrusted .deb file before installing using dpkg-deb -c package.deb and dpkg-deb -I package.deb.

Whenever possible, prefer official signed APT repositories over manually downloaded loose .deb files to ensure automatic security patch updates.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
Modern versions of APT support installing local files directly: sudo apt install ./package.deb. Unlike dpkg -i, APT automatically analyzes, downloads, and installs all missing dependencies from internet repositories simultaneously during the installation.
Use the dpkg -x command: dpkg -x package.deb /target/directory/. This unpacks the filesystem contents of the package into the target directory without modifying your system package database.
dpkg --configure -a resumes and finishes configuring any packages that were unpacked but left unconfigured due to unexpected system power loss or process interruptions.
dpkg maintains its internal database inside /var/lib/dpkg/status, which contains plain-text metadata describing every installed package, its version, architecture, and configuration state.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout