The ‘dpkg‘ command is an essential tool for managing software packages on Debian-based Linux distributions like Ubuntu and Linux Mint. It allows you to install, remove, and configure .deb packages. However, many users encounter confusing errors like "dpkg was interrupted, run dpkg –configure -a" when using dpkg.
In this comprehensive guide, we will demystify these errors and teach you how to become a dpkg power user.
Understanding Dpkg – The Heart of Debian Package Management
Dpkg is the package manager that actually handles .deb packages at a low level in Debian-based systems. It can install, remove, build essential package information databases, and configure unpacked package files among other functions.
The dpkg command works directly with .deb package files. It does not resolve software dependencies like advanced frontends such as APT do. However, dpkg allows administrators great control and provides a building block for higher-level tools.
Here is a quick overview of common dpkg operations:
- Install – Install a .deb package using
dpkg -i package.deb - Remove – Remove an installed package using
dpkg -r package - List – List installed packages with
dpkg --list - Info – Display info on an installed package using
dpkg -s package - Configure – Configure an unpacked package using
dpkg --configure package
Now let‘s explore some of the intricacies of managing software with dpkg.
Using Dpkg to Install and Remove Packages
The most basic operations with dpkg are installing and removing packages.
To install a .deb package, use the -i flag:
sudo dpkg -i my-app.deb
This will unpack the package contents and install the software.
To remove an installed package, use the -r flag:
sudo dpkg -r my-app
This will remove the package but leave configuration files behind in case you install it again later.
If you want to purge a package completely including configurations, use -P instead:
sudo dpkg -P my-app
Now let‘s look at some vital ancillary dpkg functions.
Essential Dpkg Utilities
Dpkg offers some useful utilities for managing the package database and configurations.
Listing Packages
To list all packages installed on the system, use:
dpkg --list
You can also search for specific packages using grep:
dpkg --list | grep postgresql
Package Information
To display detailed information on an installed package, use -s:
dpkg -s nano
This will show the package description, version, dependencies, and other metadata.
Package Contents
To display the files installed by a package, use -L:
dpkg -L nano
This can be useful when trying to determine which package installed a file.
Understanding Debconf – Dpkg Package Configuration
One area that confuses many dpkg users is package configuration prompts. Packages that require configuration will prompt the user for required info like credentials during installation.
This is handled by debconf, a configuration management system utilized by dpkg. Debconf allows package maintainers to create customized configuration scripts to simplify the installation process.
Some key points about debconf:
- Configuration prompts only occur during package installation/upgrades
- Prompts can request usernames, passwords, directory locations and more
- If debconf is interrupted, packages may fail to configure properly
This last point about failed configurations is why you may see "dpkg –configure -a" errors which we will elaborate on next.
How to Fix "dpkg was interrupted" Errors
A common problem that trips up dpkg users is the infamous "dpkg was interrupted" error with instructions to run dpkg --configure -a. But what does it mean and how do you fix it?
This error occurs when a package configuration script fails, is interrupted prematurely, or a required configuration file is not present. As a result, the package did not finish the installation process properly.
The key things to understand about this error are:
- It means packages on your system are only partially installed
- The unfinished configuration is what causes further installation failures
- Running
dpkg --configure -awill finalize any interrupted package configurations
Let‘s look at an example scenario.
Say you update your system:
sudo apt update && sudo apt upgrade
But halfway through the upgrade your SSH session disconnects or something interrupts the upgrade process. As a result, some packages will be unpacked but not fully configured.
Next time you use APT, it will fail and tell you to run dpkg –configure -a so the packages from the previous operation can finalize installation.
So in summary, when you see this error, run the suggested command:
sudo dpkg --configure -a
This will complete configuration on any interrupted packages in the database. After it finishes cleanly without errors, you can rerun the original APT command that failed.
Understanding this background will help diagnose similar configuration errors down the line.
Advanced Dpkg Tricks and Utilities
Now that you grasp the core functionality of dpkg, here are some advanced utilities offered by the package manager.
List Partially Installed Packages
You can explicitly list any packages with unfinished configurations using:
dpkg -C
This will display package names and problems preventing configuration like missing dependencies or files.
Check Package Integrity
To verify installed packages against the file list from the .deb, use:
dpkg --verify
This will check every package and display any issues like missing files or incorrect permissions.
Rebuild Package Database
If your main system databases with package info become corrupted or lost, you can reconstruct them with:
sudo dpkg --configure -a --force-depends
This will scan all packages on the disk and recreate your /var/lib/dpkg databases from scratch.
Reconfigure a Package
If a package configuration gets corrupted, you can forcefully reconfigure an installed program using:
sudo dpkg-reconfigure package
This is a handy way to reset package configurations instead of fully removing and reinstalling.
Understanding APT vs Dpkg
Since most Debian admins utilize APT, it can get confusing on when to use APT vs bare dpkg. Here is a quick guide on when to use each tool:
APT – Frontend tool that handles dependencies automatically. Used for installing, upgrading the system.
Dpkg – Low-level package tool. Gives you more control and access under the hood. Used for granular package management.
Generally, you will use APT for most software management on your Debian system since it resolves intricate dependencies most easily. However, dpkg is still a vital utility every admin should grasp.
Now that you understand the basics of managing packages with dpkg, some of the more cryptic package errors on a Debian system will make a lot more sense! It serves as the foundation even for user-friendly frontends like APT.
Let us know in the comments if you have any other questions on leveraging the versatile dpkg tool!


