How to Fix ‘Sub-process /usr/bin/dpkg returned an error code (1)’ in Ubuntu

Attempting to install, update, or remove software on Ubuntu or Debian-based distributions only to see the installation abort with the critical error: E: Sub-process /usr/bin/dpkg returned an error code (1) paralyzes the Advanced Package Tool (APT). Every subsequent command—whether sudo apt upgrade, sudo apt install -f, or sudo apt autoremove—abruptly fails with the identical error. In Debian package management architecture, dpkg is the low-level binary package installer called by APT. During package configuration, dpkg executes maintainer scripts (such as preinst, postinst, prerm, or postrm) located in /var/lib/dpkg/info/. When a maintainer script encounters a syntax fault, references non-existent systemd services, or fails to execute due to filesystem corruption, dpkg exits with error code 1, leaving the package in an unconfigured, half-installed state that blocks all future updates. This guide outlines proven methods to resolve dpkg error code 1 in Ubuntu.

What Causes dpkg Error Code 1 in Ubuntu?

Package configuration failures originate from broken maintainer scripts, dependency loops, and disk space limits:

  • Failing Maintainer Scripts (postinst / prerm): A package’s .postinst configuration shell script attempting to restart a failed service, query an invalid user group, or call deprecated commands.
  • Corrupted dpkg Status Database: Structural errors in /var/lib/dpkg/status preventing dpkg from recording package states.
  • Interrupted Installation Cycle: A computer shutdown, terminal closure, or kernel crash occurring mid-write while dpkg was unpacking binary payloads.
  • Exhausted Inodes or Storage: Zero available disk space or exhausted filesystem inodes on the root (/) or /var partition.
  • Circular or Broken Dependencies: Incompatible library versions introduced by mixing third-party PPAs or non-standard repositories.

Method 1: Identify the Specific Failing Package

Reviewing the terminal output immediately preceding the error message isolates which package’s script crashed.

  1. Inspect the terminal lines located 5 to 10 lines above the “returned an error code (1)” message.
  2. Look for text such as:
    Setting up package-name (1.2.3-1) ...
    dpkg: error processing package package-name (--configure):
     installed package-name package post-installation script subprocess returned error exit status 1
  3. Note the exact package-name causing the failure (e.g. samba, linux-image-generic, or mysql-server).

Method 2: Force Reconfigure and Repair Broken Dependencies

Instructing dpkg to complete pending installations often resolves transient configuration stalls.

  1. Reconfigure all pending half-installed packages:
    sudo dpkg --configure -a
  2. Clean the local download archive:
    sudo apt clean && sudo apt autoclean
  3. Fix missing and broken package dependencies:
    sudo apt install -f
  4. If the output returns without errors, run sudo apt update && sudo apt upgrade to confirm normal operation.

Method 3: Remove or Neutralize Corrupted Maintainer Scripts

If a specific package’s postinst or prerm script is permanently broken due to a bug, moving the script allows dpkg to finish installation cleanly.

  1. Identify the failing package name from Method 1 (e.g. broken-package).
  2. Move all maintainer scripts associated with that package out of /var/lib/dpkg/info/:
    sudo mv /var/lib/dpkg/info/broken-package.* /tmp/
  3. Now run the reconfiguration command again:
    sudo dpkg --configure -a
  4. Because the buggy script has been bypassed, dpkg completes package registration successfully.
  5. Run update:
    sudo apt update

Method 4: Forcefully Remove the Broken Package

If the package is not required or needs to be completely reinstalled from scratch, remove it using dpkg force flags.

  1. Execute a forceful package removal:
    sudo dpkg --remove --force-remove-reinstreq broken-package
  2. If dependencies complain, purge the package completely:
    sudo dpkg --purge --force-all broken-package
  3. Clean up orphaned dependencies:
    sudo apt autoremove -y

Method 5: Check Disk Space and Inode Availability

Exhausted disk space or inode counts prevent dpkg from writing extraction manifests.

  1. Check free disk space:
    df -h / /var
    If Use% is at 100%, delete old log files in /var/log and old kernels.
  2. Check inode usage:
    df -i /
    If IUse% is at 100%, delete thousands of tiny temporary files in /tmp or /var/tmp.

Ubuntu dpkg Error 1 Diagnostic Matrix

dpkg Error Detail Underlying Cause Effective Remediation
post-installation script returned error exit status 1 Bug in package’s postinst script in /var/lib/dpkg/info/ Move /var/lib/dpkg/info/pkg.* to /tmp and run dpkg –configure -a
package is in a very bad inconsistent state Package corrupted mid-installation Run sudo dpkg –remove –force-remove-reinstreq pkg
no space left on device Root or /var partition has 0 MB free space Run sudo apt clean; remove old kernels and system logs
dpkg status database is locked Another apt process or unattended-upgrades active Wait for background process to finish or verify with lsof

Frequently Asked Questions

Is moving files out of /var/lib/dpkg/info safe?

Yes, provided you move only the scripts belonging to the specific broken package (e.g. broken-pkg.*). The files in /var/lib/dpkg/info/ are auxiliary maintainer scripts used during setup; bypassing a buggy script allows dpkg to register the package and restores system-wide APT functionality.

Why did dpkg error code 1 appear during a kernel update?

During kernel updates, the linux-image package executes update-initramfs and update-grub in its postinst script. If your /boot partition has insufficient free space to hold the new initrd image, the script fails and throws dpkg error code 1.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.