Installing software or running sudo apt upgrade on Ubuntu only for the terminal to abort with the error: “Sub-process /usr/bin/dpkg returned an error code (1)” locks the Advanced Package Tool (APT) package manager and prevents further system updates. In Debian-based operating systems, dpkg is the core utility responsible for unpacking, configuring, and registering .deb packages. When a post-installation script fails, package archive files become corrupted during download, or package dependencies deadlock, dpkg exits with code 1 to protect system integrity. This guide explains how to repair broken dependencies, clear corrupt package metadata, and restore full package manager functionality.
Why Does dpkg Return Error Code 1?
This generic failure code indicates that a package configuration or uninstallation script failed during execution. Common triggers include:
- Corrupted Post-Installation Scripts: Faulty shell scripts located in
/var/lib/dpkg/info/failing to execute required service restarts or user creations. - Broken Package Dependencies: Conflicting libraries or partially downloaded packages leaving APT in an inconsistent state.
- Interrupted Package Operations: System power loss, accidental terminal closures, or manual terminations during an ongoing kernel or driver upgrade.
- Disk Space Exhaustion: Insufficient space in
/varor the root filesystem/to write extraction buffers. - Third-Party PPA Conflicts: Unofficial repositories supplying incompatible library versions that overwrite core Ubuntu packages.
Method 1: Force Configure Broken Packages
The first step in resolving dpkg failures is instructing the package manager to attempt configuring all unpacked but unconfigured packages.
- Open your terminal and run the configuration repair command:
sudo dpkg --configure -a - If the command completes without errors, run the package dependency resolver:
sudo apt --fix-broken install - Update your package lists to verify resolution:
sudo apt update && sudo apt upgrade -y
Method 2: Remove the Problematic Package Info Files
If the error output identifies a specific package (for example, “package-name”), corrupted scripts in /var/lib/dpkg/info/ are typically preventing removal or setup.
- Identify the exact package name mentioned directly above the error code in your terminal.
- Move the package’s configuration files to a temporary backup directory:
sudo mv /var/lib/dpkg/info/package-name.* /tmp/(Replace
package-namewith the exact name of the offending package.) - Re-run the configuration command:
sudo dpkg --configure -a - Force reinstall or remove the package cleanly:
sudo apt --fix-broken install
Method 3: Clear Corrupted APT Package Cache
Damaged .deb archives stored in the local download cache can cause recurring checksum and extraction failures.
- Clear the local APT cache repository:
sudo apt clean sudo apt autoclean - Remove orphaned packages:
sudo apt autoremove --purge -y - Refresh repositories:
sudo apt update
Method 4: Force Removal of Locked or Damaged Packages
If a broken package refuses to configure or purge normally via apt, force removal using dpkg directly:
sudo dpkg --remove --force-remove-reinstreq package-name
After forced removal, run sudo apt update to synchronize package manifests.
Method 5: Check and Free Disk Space
Verify that your root partition has not reached 100% capacity, which silently aborts dpkg operations:
df -h /
If available space is below 1 GB, delete old system logs and obsolete kernels:
sudo journalctl --vacuum-time=3d
sudo apt --purge autoremove -y