Introduction
The "Sub-process /usr/bin/dpkg returned an error code (1)" error message indicates a problem with the dpkg package installer. The error occurs in Ubuntu and other Debian-based systems after a failed software installation or if the installer becomes corrupted.
This guide will show you how to resolve the "Sub-process /usr/bin/dpkg returned an error code (1)" error using multiple methods.
Prerequisites
- A user account with sudo privileges.
- Access to the terminal (Ctrl–Alt–T).
How to Fix "sub-process /usr/bin/dpkg returned an error code (1)"
If the dpkg
package manager becomes corrupted, users get the "sub-process /usr/bin/dpkg returned an error code (1)" error. The corruption causes any new software installation to throw an error message. The screenshot below shows an example of the error on Ubuntu:
There are several possible solutions for the issue, from straightforward ones to more complex processes. The sections below start with the simplest method.
Method 1: Reconfigure dpkg Database
Reconfiguring the dpkg
package database is the most straightforward solution for the error and the first thing you should try. This method can repair the database if it has become corrupted.
To reconfigure the database, open the terminal and run the following command:
sudo dpkg --configure -a
The -a
flag tells dpkg
to configure all packages that are currently installed but have not been configured yet.
The command reconfigures packages that have been installed but not properly configured. An interruption during package installation or update can cause the database to become corrupt.
Method 2: Fix Broken Dependencies
If the first method does not work, try to fix the dependencies in the package installer. Broken dependencies refer to missing or incompatible software components that can cause a program to malfunction. They occur when a download is interrupted or when there is a problem with the cached download.
To fix the dependencies, run the command below:
sudo apt install -f
The -f
option is short for --fix-broken
, and you can specify either the short or the long form. It repairs any broken dependencies in your package manager.
Method 3: Remove Bad Package and Associated Files
If you know which software is causing the error on your system, you can remove it. Open the terminal and use the syntax below to remove a package and all its associated files:
sudo apt remove --purge [package_name]
- Replace
[package_name]
with the name of the package causing the error. - The
--purge
option directs the system to remove the configuration files in addition to uninstalling. This helps get rid of all traces of the malfunctioning software.
Alternatively, delete the software files manually. Follow the steps below:
1. Open the terminal and use the syntax below to list all the files you need to remove:
sudo ls -l /var/lib/dpkg/info | grep -i [package_name]
The /var/lib/dpkg/info directory contains information files for installed packages managed by dpkg
, including details such as package names, versions, dependencies, and installation scripts.
Replace [package_name]
with the name of the package in question. For example:
In the example above, the command generates a list of all references to the Apache server.
2. Remove the files from the list using the syntax below:
sudo mv /var/lib/dpkg/info/[package_name].* /tmp
The mv command moves the files to the /tmp directory, where they cannot affect the dpkg
package manager.
3. To complete the process, update the system package repository:
sudo apt update
After updating the repository, reinstall the broken software.
Method 4: Remove Unused Packages
Old, outdated, or unused packages could be the cause of the error. To solve the problem, remove unused software packages.
Run the following command in the terminal:
sudo apt autoremove
The command removes any automatically installed packages that are no longer required as dependencies for other installed packages. Next, run the following command to remove downloaded package files (.deb) from the local package cache:
sudo apt clean
Method 5: Overwrite Bad Package
If you know the name of the package that is causing the problem, you can force an overwrite of that package.
Use the following syntax and replace [package_name]
with the actual package name:
sudo dpkg -i --force-overwrite /var/cache/apt/archives/[package_name]
Warning: Only try this method if none of the previous ones have helped. Overwriting a package is dangerous and may lead to a broken system (it installs the new packages but may cause issues if both packages try to use the same library/file/binary).
If you do not know the full package name, search for it using the ls command:
ls /var/cache/apt/archies/[package_name]
Replace [package_name]
with the name of your software. The command returns any instances of that package name. Note the exact filename and use it in the previous command.
Conclusion
The dpkg
error message indicates that there is a problem with the package installer, which is commonly caused by an interrupted installation process or a corrupted database. This tutorial has shown several methods to fix the dpkg
error message.
Next, see how to fix the Could not get lock /var/lib/dpkg/lock error in Ubuntu or learn to kill an unresponsive process.