Running package installations, system upgrades, or removals in Ubuntu using apt install or apt upgrade only to have the terminal abort with the terminal error: ‘Errors were encountered while processing: package-name’ and ‘E: Sub-process /usr/bin/dpkg returned an error code (1)’ blocks all future package management. In Debian and Ubuntu systems, dpkg error code 1 signals that an installation or post-installation maintainer script (such as postinst or prerm) exited with a non-zero exit code due to broken dependencies, missing configuration files, or corrupted package metadata.
Why Does dpkg Return Error Code 1 in Ubuntu?
When apt downloads a package, dpkg unpacks binaries and executes shell maintainer scripts located in /var/lib/dpkg/info/. Common root causes include:
- Failing Maintainer Scripts (postinst/prerm): The package configuration script attempting to create system users, start services, or copy configuration files that fail due to missing dependencies.
- Corrupted dpkg Package Metadata: Damaged
.listor.md5sumsfiles in/var/lib/dpkg/info/preventing dpkg from verifying installed file trees. - Unfinished or Interrupted Package Installations: An interrupted terminal session or power cut leaving packages in a half-configured (
unpackedorhalf-configured) state. - Conflicting PPA or Third-Party Repositories: Third-party package archives supplying binaries compiled against incompatible shared library versions.
- Exhausted Storage or Inode Space: A full
/bootor/varpartition preventing kernel images or database files from writing to disk.
Step 1: Reconfigure Unfinished Packages
Instruct dpkg to resume and complete all pending package configurations.
- Open your terminal and execute:
sudo dpkg --configure -a - If the command completes without errors, try updating your system again:
sudo apt update && sudo apt upgrade -y
Step 2: Force Dependency Resolution
Use apt’s built-in dependency fixer to download missing prerequisites or safely remove incompatible packages.
- Run the fix-broken install routine:
sudo apt --fix-broken install - Review the suggested removals and dependencies. Type
Yand press Enter to proceed.
Step 3: Move Corrupted Package Info Files
If a specific package continually fails due to a broken maintainer script, temporarily isolating its metadata allows dpkg to bypass the failing hook.
- Identify the exact package name cited in the error output (e.g.
package-name). - Move the package’s info files out of the dpkg database:
sudo mv /var/lib/dpkg/info/package-name.* /tmp/ - Update package lists and reconfigure:
sudo apt update sudo dpkg --configure -a - Reinstall or cleanly purge the package:
sudo apt install --reinstall package-name
Step 4: Clean the APT Package Cache
Corrupted deb packages stored in local archives can repeatedly fail hash checks and configuration.
- Clear obsolete and downloaded deb archives:
sudo apt clean sudo apt autoclean sudo apt autoremove -y
Step 5: Check Free Disk and Inode Space
A full /boot partition filled with accumulated old Linux kernel images is a frequent cause of dpkg error code 1 during kernel upgrades.
- Inspect available disk space:
df -h / /boot /var - Inspect available filesystem inodes:
df -i / /boot /var - If
/bootis at 100% capacity, remove obsolete kernel images safely:sudo apt autoremove --purge
Reconfiguring pending packages with dpkg, repairing broken dependencies, and removing corrupted maintainer scripts resolves dpkg error code (1) in Ubuntu.