How to fix subprocess installed post-removal script returned error exit status 1 in APT
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- Reconfigure all pending packages
- Fix broken dependencies
- Clean apt cache and retry
- Fix DOS line endings in the script (if applicable)
sudo dpkg --configure -asubprocess 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
- 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
- Missing shared libraries or dependencies that the script needs (e.g., libcrypto.so.1.1)
- A mount point still exists where the script expects an empty directory to be removed
- The dpkg database is corrupted or packages are in an inconsistent state
- 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"
This is the first and safest fix. It tells dpkg to process and configure all partially installed packages:
sudo dpkg --configure -aThe -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.
If the above doesn't work, use apt to fix broken dependencies:
sudo apt install -fOr equivalently:
sudo apt install --fix-brokenThis command attempts to repair broken package dependencies and may complete the installation of the problematic package.
Clear the apt cache and try the operation again:
sudo apt clean
sudo apt update
sudo apt upgradeThis removes potentially corrupted package files and refreshes the package index.
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:
# 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:
sudo apt remove <package-name>Replace <package-name> with the actual package name from the error message (without the .postrm extension).
If the script contains a failing command, you can disable the -e flag (exit on error):
# 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>.postrmThis makes the script continue even if individual commands fail. Retry the operation after this change.
If standard removal fails, try forcing it with --force options:
# 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 -aUse 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
- ๐APT Official Documentation
- ๐ฌUbuntu Forums: [SOLVED] subprocess post-removal script error(Stack Overflow)