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.

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.
- Prerequisites and Supported Releases
- Understanding the Relationship Between dpkg and apt
- Step 1: Installing a Local .deb Package with dpkg -i
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.
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.
Comprehensive Linux system administrator guide on using the low-level Debian package management tool (dpkg) on Ubuntu 24.04 LTS (Noble Numbat) and 22.04 LTS. Explains how dpkg interacts with the APT packaging layer, installing local .deb files with dpkg -i, resolving unmet dependencies with apt --fix-broken install, querying installed files with dpkg -L and dpkg -S, and purging configuration files.
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:
- A server or computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
- A non-root user account with
sudoadministrative privileges. - Access to a bash terminal shell.
- A local
.debpackage 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 / Feature | dpkg (Low-Level Engine) | apt (High-Level Frontend) |
|---|---|---|
| Primary Role | Installs, unpacks, and queries local .deb files directly on disk | Downloads packages from remote internet repositories and calculates dependency trees |
| Dependency Resolution | None (Fails if required prerequisite packages are missing) | Automatic (Recursively downloads and installs all prerequisite dependencies) |
| Target Operand | Accepts local file paths (e.g. dpkg -i package.deb) | Accepts package names (e.g. apt install nginx) |
| Database Maintenance | Maintains local package database in /var/lib/dpkg/status | Maintains 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:
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) ...
| Command | Action Performed | Configuration Files Retained? |
|---|---|---|
sudo dpkg -r package | Removes binary executables, libraries, and man pages | Yes (Keeps custom configuration files in /etc/) |
sudo dpkg -P package | Completely purges all binaries, libraries, and configuration files | No (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.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
apt vs apt-get: The Difference and When to Use Each— Compare high-level package management frontends with low-level dpkg.- How to Fix APT and dpkg Lock Errors on Ubuntu and Debian — Diagnose and resolve database lock errors in dpkg.
apt update vs apt upgrade vs apt full-upgrade— Master system updates and package index mechanics.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
sudo apt install ./package.deb. Unlike dpkg -i, APT automatically analyzes, downloads, and installs all missing dependencies from internet repositories simultaneously during the installation.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.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
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.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!