How to Fix ‘Sub-process /usr/bin/dpkg Returned an Error Code (2)’ in Ubuntu

Managing packages via apt-get install or apt upgrade in Ubuntu should execute predictably. However, encountering the severe package error ‘dpkg: error: parsing file ‘/var/lib/dpkg/status’ near line …: field name ‘…’ must be followed by a colon. E: Sub-process /usr/bin/dpkg returned an error code (2)’ completely blocks all package installations and system upgrades.

While error code 1 typically indicates a script failure within an individual package, dpkg error code 2 signals structural corruption within the core dpkg database itself – specifically the /var/lib/dpkg/status or /var/lib/dpkg/available files following an abrupt power loss or hard crash during package configuration. Following this tutorial will safely restore your dpkg database.

Restore the /var/lib/dpkg/status File from Automated Backups

Ubuntu automatically maintains recent backup copies of the core dpkg status database inside the /var/backups/ directory, allowing you to recover from database corruption without reinstalling your system.

  1. Open your terminal console.
  2. Back up the currently damaged status file:
    sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.corrupted
  3. Inspect available automated status backups:
    ls -l /var/backups/dpkg.status*
  4. Restore the most recent uncorrupted backup:
    sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
    (If dpkg.status.0 is also corrupted, extract an older compressed archive such as sudo zcat /var/backups/dpkg.status.1.gz > /tmp/status && sudo cp /tmp/status /var/lib/dpkg/status).
  5. Verify that dpkg can parse the restored file:
    sudo dpkg --configure -a

Reconstruct Available Package Metadata Lists

If the error references /var/lib/dpkg/available, clearing and rebuilding the package metadata table restores functionality.

  1. Back up and replace the available file with an empty container:
    sudo cp /var/lib/dpkg/available /var/lib/dpkg/available.bak
    sudo touch /var/lib/dpkg/available
  2. Reconstruct the metadata list using dselect or dpkg:
    sudo dpkg --clear-avail
  3. Update your APT repository caches to repopulate fresh package indexes:
    sudo apt-get clean && sudo apt-get update

Resolve Broken Dependencies and Re-synchronise Repositories

Once the dpkg status database parses cleanly, resolve any half-installed packages or unmet dependencies.

  1. Force APT to repair broken dependency trees:
    sudo apt-get install -f
  2. Audit for any lingering broken packages:
    sudo dpkg --audit
  3. Run a complete upgrade to verify system health:
    sudo apt update && sudo apt upgrade -y

Get the best tech tips delivered straight to your inbox.

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