Debian / Ubuntu Package Troubleshooting: subprocess post-removal script returned error exit status xx

Here is a quick way to fix half installed packages under Debian / Ubuntu Linux.

If you see an error while removing or installing debian / ubuntu package that read as follows:

(Reading database … 147148 files and directories currently installed.)
Preparing to replace octopussy 0.9.6.2 (using octopussy_0.9.6.2_all.deb) …
Unpacking replacement octopussy …
dpkg: warning – old post-removal script returned error exit status 10
dpkg – trying script from the new package instead …
dpkg: error processing octopussy_0.9.6.2_all.deb (–install):
subprocess new post-removal script returned error exit status 10
dpkg: error while cleaning up:
subprocess post-removal script returned error exit status 10
Errors were encountered while processing:
octopussy_0.9.6.2_all.deb

In above octopussy package is not getting removed because of script error. Mostly these are shell script written using /bin/sh. These scripts called with -e option which means if not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an && or || operator. In short shell scripts will abort with an error if something fails. To fix this problem visit /var/lib/dpkg/info directory
# cd /var/lib/dpkg/info
Now find out files in following format:
packagename.*
octopussy.*
$ ls octopussy.*
Now open each file and find out line that read as follows:
#/bin/sh -e
Replace with
#/bin/sh
Save and close all the files. Now run apt-get / dpkg command again to remove package:
# apt-get --purge remove octopussy
OR
# dpkg -r octopussy

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
22 comments… add one
  • Umar Hayat Nov 26, 2014 @ 22:05

    Thanks It saved my life

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.