How to Fix ‘Package is in a very bad inconsistent state’ in Ubuntu

When an APT installation or upgrade process in Ubuntu is interrupted by an unexpected power cut, terminal crash, or broken pre-removal script, package management operations grind to an absolute halt. Any subsequent attempt to install, remove, or upgrade packages fails with a severe error: “dpkg: error processing package [packagename] (–remove): package is in a very bad inconsistent state; you should reinstall it before attempting a removal.”

This message signifies that the low-level Debian package manager (dpkg) has recorded the package as half-installed or half-configured inside the status database (/var/lib/dpkg/status). Because package integrity is compromised, dpkg refuses to execute standard commands until the inconsistency is cleared. This guide details how to force remove the damaged package and restore healthy package management.

Method 1: Force Removal Using dpkg –remove –force-remove-reinstreq

The standard apt-get remove command respects safety boundaries and will refuse to touch packages flagged for required reinstallation. The low-level dpkg utility provides a direct force flag designed specifically for this scenario.

  1. Press Ctrl + Alt + T to launch the terminal.
  2. Identify the exact package name reported in the error message (e.g. samba-common or libssl1.1).
  3. Force the removal of the inconsistent package by running:
    sudo dpkg --remove --force-remove-reinstreq [packagename]
    Replace [packagename] with the exact name of the broken package.
  4. If the package is successfully removed, repair broken package dependencies:
    sudo apt-get install -f
  5. Update your package lists to verify normal operation:
    sudo apt-get update && sudo apt-get upgrade

Method 2: Clear Corrupted Package Info Files

If forcing removal with --force-remove-reinstreq fails because pre-removal scripts (.prerm) or post-installation scripts (.postinst) throw execution errors, moving the package’s script files aside allows dpkg to bypass the failing hook.

  1. Open the terminal window.
  2. Navigate to the dpkg package information directory:
    cd /var/lib/dpkg/info
  3. List all script files associated with the broken package:
    ls -la [packagename].*
  4. Move these script files into a temporary backup location:
    sudo mkdir -p /tmp/dpkg-backup
    sudo mv [packagename].* /tmp/dpkg-backup/
  5. Now re-run the removal command:
    sudo dpkg --remove --force-remove-reinstreq [packagename]
  6. Because the failing maintenance scripts were removed, dpkg will cleanly unregister the package files and delete its status flags.

Method 3: Manually Clean the dpkg Status Database Entry

If dpkg still complains about an inconsistent state, you can manually edit the status database entry to change the package status from broken to purged.

  1. Create an immediate backup copy of your status database before editing:
    sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.backup
  2. Open the status file in the nano text editor:
    sudo nano /var/lib/dpkg/status
  3. Press Ctrl + W, type Package: [packagename], and press Enter to find the package definition block.
  4. Look for the line that reads:
    Status: install ok reinstreq
    or
    Status: deinstall ok config-files
  5. Either delete the entire paragraph describing that specific package (from Package: ... down to the empty newline before the next package), or change the Status line to:
    Status: purge ok not-installed
  6. Press Ctrl + O followed by Enter to save the file, then press Ctrl + X to exit nano.
  7. Run the package fixer command:
    sudo apt-get update && sudo apt-get install -f

Method 4: Reinstall the Clean Package from Upstream

If the broken package is an essential system library that cannot simply be deleted without removing critical desktop packages, force-downloading a fresh .deb package and reinstalling it resolves the state cleanly.

  1. Download the official Debian archive for the package without installing it:
    sudo apt-get download [packagename]
  2. Force the reinstallation of the downloaded .deb archive over the corrupt installation:
    sudo dpkg -i --force-all [packagename]*.deb
  3. Configure unconfigured packages:
    sudo dpkg --configure -a
  4. Clean up temporary downloaded files:
    rm [packagename]*.deb

dpkg Inconsistent State Recovery Reference Table

The table below provides a quick reference for resolving corrupted package states:

Stage / Failure Point Cause Command
APT rejects remove command reinstreq flag set in dpkg status sudo dpkg --remove --force-remove-reinstreq <pkg>
prerm / postinst script failure Broken maintainer bash script sudo mv /var/lib/dpkg/info/<pkg>.* /tmp/
Package database locked or corrupt Orphaned dpkg lock or status corruption Edit /var/lib/dpkg/status (after backup)
Essential system library broken Missing binary or broken symlink sudo apt-get download <pkg> && sudo dpkg -i --force-all *.deb

Preventing dpkg Status Database Corruption

To avoid package state corruption, never close your terminal emulator or power off your computer while an APT transaction is actively writing files to disk. If an update appears to freeze, wait at least several minutes to verify whether the disk is performing post-installation triggers before attempting any manual intervention.

Get the best tech tips delivered straight to your inbox.

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