How to fix subprocess installed post-removal script returned error exit status 1 in APT

APTINTERMEDIATEMEDIUMUpdated Dec 29, 2025ยท 287 views

The dpkg post-removal script error occurs when a package's cleanup script fails during uninstallation or upgrade. This typically affects kernel images, system libraries, or packages with custom removal logic. Fix it by reconfiguring dpkg, repairing broken dependencies, or manually editing the problematic script.

Quick fix

Fixes 1

sudo dpkg --configure -a
  1. Reconfigure all pending packages
  2. Fix broken dependencies
  3. Clean apt cache and retry
  4. Fix DOS line endings in the script (if applicable)
apt โ€” error
sudo dpkg --configure -a
subprocess installed post-removal script returned error exit status 1

What this error means

When you remove or upgrade a package on Debian/Ubuntu systems, dpkg executes a "post-removal script" (postrm) to clean up package-specific configurations, directories, or system state. If this script returns exit status 1 (or any non-zero value), dpkg treats it as a failure and reports "subprocess installed post-removal script returned error exit status 1". The error indicates that the cleanup process didn't complete successfully. This can leave the system in an inconsistent state where the package is partially removed or the dpkg database is locked, preventing further package operations until resolved.

Typical symptoms

  • apt remove, apt upgrade, or apt purge commands fail with the post-removal script error
  • Package manager becomes stuck and won't proceed with other operations
  • System shows broken dependencies or unmet dependencies
  • Kernel upgrade or removal fails mid-process
  • dpkg database lock file exists or dpkg reports "dpkg: error processing package..."

Common causes

  1. A package's post-removal script references a file or directory that no longer exists or has changed
  2. The post-removal script contains a command that fails (e.g., update-grub fails, initramfs-tools returns error)
  3. The script was saved with DOS line endings (CR-LF) instead of Unix line endings, causing shell interpreter not found
  4. Missing shared libraries or dependencies that the script needs (e.g., libcrypto.so.1.1)
  5. A mount point still exists where the script expects an empty directory to be removed
  6. The dpkg database is corrupted or packages are in an inconsistent state
  7. Kernel-related scripts (in /etc/kernel/postrm.d/) fail due to grub-customizer or other GRUB modifications

How to fix "subprocess installed post-removal script returned error exit status 1"

1Reconfigure all pending packages

This is the first and safest fix. It tells dpkg to process and configure all partially installed packages:

bash
sudo dpkg --configure -a

The -a flag means "all" and --configure tells dpkg to complete configuration of unpacked packages. This often resolves the error if the package was interrupted during installation.

2Fix broken dependencies

If the above doesn't work, use apt to fix broken dependencies:

bash
sudo apt install -f

Or equivalently:

bash
sudo apt install --fix-broken

This command attempts to repair broken package dependencies and may complete the installation of the problematic package.

3Clean apt cache and retry

Clear the apt cache and try the operation again:

bash
sudo apt clean
sudo apt update
sudo apt upgrade

This removes potentially corrupted package files and refreshes the package index.

4Fix DOS line endings in the script (if applicable)

If the post-removal script has DOS line endings (CR-LF), it will fail. First, identify the problematic package name from the error message, then fix it:

bash
# If you have dos2unix installed:
sudo dos2unix /var/lib/dpkg/info/<package-name>.postrm

# Or replace the script with a minimal placeholder:
sudo sh -c 'echo "#!/bin/sh" > /var/lib/dpkg/info/<package-name>.postrm'

After fixing the script, retry the operation:

bash
sudo apt remove <package-name>

Replace <package-name> with the actual package name from the error message (without the .postrm extension).

5Manually edit the post-removal script

If the script contains a failing command, you can disable the -e flag (exit on error):

bash
# First, back up the dpkg database
sudo cp -r /var/lib/dpkg /var/lib/dpkg.backup

# Edit the postrm script to comment out the set -e line
sudo sed -i 's/^set -e/#set -e/g' /var/lib/dpkg/info/<package-name>.postrm

This makes the script continue even if individual commands fail. Retry the operation after this change.

6Force package removal or purge (last resort)

If standard removal fails, try forcing it with --force options:

bash
# Attempt forced removal
sudo apt remove --allow-downgrades --allow-remove-essential --allow-change-held-packages <package-name>

# Or use dpkg directly with --force-all
sudo dpkg --remove --force-all <package-name>

# Then clean up
sudo apt install -f
sudo dpkg --configure -a

Use this only after trying other methods, as it bypasses safety checks.

Advanced notes

For kernel-related post-removal errors, the issue often involves /etc/kernel/postrm.d/ scripts failing, particularly update-grub or initramfs-tools. These are triggered when removing linux-image packages. If grub-customizer was used to modify GRUB configuration, it can break these scripts. In such cases, reinstalling grub-common or using the standard grub tools instead of grub-customizer may be necessary.

For DKMS (Dynamic Kernel Module Support) packages, the post-removal script may fail if the module failed to compile or uninstall. Run sudo apt remove <dkms-package> and then reinstall it cleanly.

If none of these methods work, as an absolute last resort, you can manually edit /var/lib/dpkg/status and /var/lib/dpkg/status-old to remove the problematic package entry entirely, but only do this with a backup of these files first. This is dangerous and should only be considered if the system is unusable and other methods have failed.

Frequently asked questions

What does "1" mean?
When you remove or upgrade a package on Debian/Ubuntu systems, dpkg executes a "post-removal script" (postrm) to clean up package-specific configurations, directories, or system state. If this script returns exit status 1 (or any non-zero value), dpkg treats it as a failure and reports "subprocess installed post-removal script returned error exit status 1". The error indicates that the cleanup process didn't complete successfully.
How do I fix "1"?
The dpkg post-removal script error occurs when a package's cleanup script fails during uninstallation or upgrade. This typically affects kernel images, system libraries, or packages with custom removal logic. Fix it by reconfiguring dpkg, repairing broken dependencies, or manually editing the problematic script.
What causes "1"?
A package's post-removal script references a file or directory that no longer exists or has changed The post-removal script contains a command that fails (e.g., update-grub fails, initramfs-tools returns error) The script was saved with DOS line endings (CR-LF) instead of Unix line endings, causing shell interpreter not found
Is the "1" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading