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.
- Open your terminal console.
- Back up the currently damaged status file:
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.corrupted - Inspect available automated status backups:
ls -l /var/backups/dpkg.status* - 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 assudo zcat /var/backups/dpkg.status.1.gz > /tmp/status && sudo cp /tmp/status /var/lib/dpkg/status). - 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.
- Back up and replace the available file with an empty container:
sudo cp /var/lib/dpkg/available /var/lib/dpkg/available.baksudo touch /var/lib/dpkg/available - Reconstruct the metadata list using dselect or dpkg:
sudo dpkg --clear-avail - 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.
- Force APT to repair broken dependency trees:
sudo apt-get install -f - Audit for any lingering broken packages:
sudo dpkg --audit - Run a complete upgrade to verify system health:
sudo apt update && sudo apt upgrade -y