This error occurs when a package's pre-removal script (prerm) fails during package removal or upgrade. It's typically caused by missing services, corrupted scripts, or database issues. Can usually be fixed by cleaning package cache, configuring dpkg, or forcefully removing the problematic package.
The dpkg package manager runs pre-removal scripts (prerm) before uninstalling packages. When one of these scripts fails and exits with a non-zero status code, dpkg reports this error. This typically happens because: 1. A required service isn't running during uninstallation 2. The script was passed an unexpected argument 3. The script has corrupted or duplicate code 4. The dpkg database is corrupted 5. Trigger files are empty or damaged The error message indicates that dpkg detected a failure in the package removal process and stopped to prevent data loss.
Start with basic cleanup and reconfiguration commands. This fixes many corrupted package database issues:
sudo apt-get clean
sudo apt-get update
sudo dpkg --configure -aThen try removing or upgrading the package again:
sudo apt-get upgradeThis approach is non-destructive and resolves the majority of pre-removal script errors. If this works, you're done.
If dpkg reports broken dependencies after the above, use apt's fix-broken-install feature:
sudo apt-get install -f
sudo apt-get upgradeThe -f flag tells apt to try to fix broken package dependencies. This resolves dependency conflicts that may be preventing the pre-removal script from running correctly.
If the package still won't budge, use dpkg's force-remove options. First identify the exact package name from the error message:
sudo dpkg --remove --force-remove-reinstreq PACKAGE_NAMEReplace PACKAGE_NAME with the actual package (e.g., mariadb-server, docker.io, etc.).
If that fails, you can move the problematic script files and try again:
sudo mv /var/lib/dpkg/info/PACKAGE_NAME.prerm /tmp/
sudo mv /var/lib/dpkg/info/PACKAGE_NAME.postrm /tmp/
sudo dpkg --remove --force-remove-reinstreq PACKAGE_NAMEThen reinstall the package if needed:
sudo apt-get install PACKAGE_NAMEIf you control the package or know it's safe, you can edit the pre-removal script directly:
sudo nano /var/lib/dpkg/info/PACKAGE_NAME.prermEither fix the script logic or replace the entire contents with a safe no-op:
#!/bin/bash
exit 0Save the file (Ctrl+O, Enter, Ctrl+X), then attempt package removal again.
In rare cases, dpkg lock files may be stuck. Clear them and reconfigure:
sudo rm -f /var/lib/dpkg/lock-frontend
sudo rm -f /var/lib/dpkg/lock
sudo rm -f /var/cache/apt/archives/lock
sudo dpkg --configure -aAfter clearing locks, retry your apt operations.
Pre-removal script failures are often package-specific. Common culprits include Docker, MariaDB, and Ubuntu Advantage Tools packages that fail to stop services cleanly.
For services like Docker, the pre-removal script tries to gracefully stop the daemon. If the daemon is already stopped or has crashed, the script fails with exit status 1. This is usually harmless and can be safely forced through.
Some packages (especially those using dh_installinit) have duplicate code between the maintainer script and the init system handler, causing conflicts. If you're maintaining a package, review your prerm script for duplicated service stop/status commands.
In containerized environments (Docker, LXC, systemd-nspawn), pre-removal scripts may fail because essential services or system tools are not available. Use force-remove options in these cases.
Always keep package metadata backups in /var/lib/dpkg/info before making manual edits to .prerm or .postrm files.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT