How to fix E: Sub-process /usr/bin/dpkg returned an error code (2) in APT

APTINTERMEDIATEHIGHUpdated Dec 29, 2025· 234 views

The dpkg error code (2) typically occurs when the package manager encounters file system or permission issues, corrupt package lists, or incomplete installations. This can usually be fixed by reconfiguring dpkg, fixing broken dependencies, or removing lock files.

Quick fix

Fixes 2

sudo dpkg --configure -a
  1. Reconfigure all pending packages
  2. Fix broken dependencies
  3. Remove stale lock files
  4. Recreate missing dpkg directories
apt — error
sudo dpkg --configure -a
E: Sub-process /usr/bin/dpkg returned an error code (2)

What this error means

The "E: Sub-process /usr/bin/dpkg returned an error code (2)" error indicates that the Debian Package Manager (dpkg) has encountered a critical error while processing packages. This error occurs when apt tries to run dpkg as a subprocess to install, remove, or configure packages, but dpkg encounters an issue and exits with error code 2. The error can stem from several sources: corrupted package database files, missing directories in /var/lib/dpkg/, file permission issues, stale lock files preventing dpkg from running, or incomplete package installations from previous attempts. Unlike error code 1, which typically indicates configuration issues, error code 2 usually points to more serious structural problems with the package manager state.

Typical symptoms

  • apt install, apt upgrade, or apt autoremove commands fail with this error
  • System updates cannot be completed
  • New packages cannot be installed
  • Package removal operations fail
  • Error appears even when running apt with sudo

Common causes

  1. Corrupted or missing files in /var/lib/dpkg/ directory (particularly in /var/lib/dpkg/info/ or /var/lib/dpkg/updates/)
  2. Stale lock files preventing dpkg from accessing package database
  3. Missing critical directories like /var/lib/dpkg/updates/
  4. File system corruption or permission issues on the system partition
  5. Incomplete or interrupted package installation from a previous failed operation
  6. Outdated dpkg version relative to installed packages

How to fix "E: Sub-process /usr/bin/dpkg returned an error code (2)"

1Reconfigure all pending packages

The most common fix is to reconfigure all packages that are installed but not properly configured:

bash
sudo dpkg --configure -a

The -a flag tells dpkg to configure all unconfigured packages. This resolves issues where package installation was incomplete or interrupted.

2Fix broken dependencies

If reconfiguring dpkg doesn't resolve the issue, use apt to fix broken dependencies:

bash
sudo apt --fix-broken install

This command will attempt to resolve dependency issues and complete interrupted installations. The --fix-broken (or -f) flag specifically addresses broken package dependencies.

3Remove stale lock files

If the above steps don't work, dpkg may be blocked by lock files that weren't cleaned up properly. Remove them carefully:

bash
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock

After removing these lock files, attempt to run your apt command again. You may also need to reconfigure dpkg again with sudo dpkg --configure -a.

4Recreate missing dpkg directories

The dpkg updates directory may be missing. Create it if it doesn't exist:

bash
sudo mkdir -p /var/lib/dpkg/updates

Then update your package lists and try again:

bash
sudo apt update
sudo apt upgrade

This directory is used by dpkg to track ongoing operations and is sometimes removed during system cleanup or after crashes.

5Remove problematic package info files

If a specific package's metadata is corrupted (evident from error messages mentioning a specific package), you can remove its info file:

bash
sudo rm /var/lib/dpkg/info/[package-name].list

Replace [package-name] with the actual package name from the error message. After removal, update and upgrade:

bash
sudo apt update
sudo apt upgrade

Use this method only when you've identified the specific problematic package.

6Check file system integrity (advanced)

If none of the above fixes work, there may be underlying file system corruption. Check your system logs for filesystem errors:

bash
sudo dmesg | grep -i error

Look for messages about filesystem issues. If you find concerning errors, you may need to run filesystem check tools like fsck (ideally in single-user mode or from a live USB), but be cautious as this can be destructive if run incorrectly.

Advanced notes

Error code 2 specifically indicates a file system or permission issue rather than a package configuration problem. If you encounter this repeatedly, it may indicate:

- Filesystem issues: Run sudo smartctl -a /dev/sda (replace sda with your disk) to check disk health
- SELinux/AppArmor: Security policies may prevent dpkg from accessing files. Check sudo getenforce and sudo aa-status
- Read-only filesystem: Your /var/lib/dpkg directory may have become read-only. Check with mount | grep /var
- Disk space: Ensure sufficient space exists: df -h /var

In rare cases where the dpkg database is severely corrupted and the above steps fail, you may need to manually reconstruct the database state, which is an advanced procedure best documented in the Debian dpkg manual.

Frequently asked questions

What does "2" mean?
The "E: Sub-process /usr/bin/dpkg returned an error code (2)" error indicates that the Debian Package Manager (dpkg) has encountered a critical error while processing packages. This error occurs when apt tries to run dpkg as a subprocess to install, remove, or configure packages, but dpkg encounters an issue and exits with error code 2. The error can stem from several sources: corrupted package database files, missing directories in /var/lib/dpkg/, file permission issues, stale lock files preventing dpkg from running, or incomplete package installations from previous attempts.
How do I fix "2"?
The dpkg error code (2) typically occurs when the package manager encounters file system or permission issues, corrupt package lists, or incomplete installations. This can usually be fixed by reconfiguring dpkg, fixing broken dependencies, or removing lock files.
What causes "2"?
Corrupted or missing files in /var/lib/dpkg/ directory (particularly in /var/lib/dpkg/info/ or /var/lib/dpkg/updates/) Stale lock files preventing dpkg from accessing package database Missing critical directories like /var/lib/dpkg/updates/
Is the "2" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading