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

Posted on in Categories Debian Linux, GNU/Open source, Linux, package management, Troubleshooting, Ubuntu Linux last updated May 11, 2008

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

22 comment

  1. Hey,

    very nice tip man I thought that I will never remove my package !!!

    Just one thing I had in my files in /var/lib/dpkg/info/ one of my packageÅ› file with a #!/bin/sh -e but others files were with a “good” #!/bin/sh and 2 lines after a vicious line :
    set -e
    You need to comment it !!!

    Thanks thanks thanks

    jeff

  2. Thanks man, I really appreciate your post, I didn’t had any problem of the above mentioned, mine was a corrupted postrm file, that I was able to figure out following your post.

    Thanks again

  3. I still can’t get the failed install of Bittorrent and Banshee to remove.

    E: banshee: subprocess installed post-removal script returned error exit status 2
    E: bittorrent-gui: subprocess installed post-removal script returned error exit status 2

  4. For those of you that (even after following these awesome directions) can’t get your package uninstalled, here is the sure fire method:

    WARNING: BACK UP /var/lib/dpkg/* before doing this!

    Edit /var/lib/dpkg/status
    Edit /var/lib/dpkg/status-old

    Remove the section in these files for your package, then save the file.

    BE CAREFUL!

    apt-get update && apt-get upgrade

    your package should be gone!

    1. ahhhh.
      that did it.
      the posted method didn’t work for me, it just gave more errors about yet more missing files after editing the -e lines out.
      the manual removal from the two files you specified worked great!
      thank you.

  5. Thanks for the tip!

    I don’t know how much of these files have to be edited, so I used sed in the following manner:

    for i in `ls octopuss*` ; do sed -ie ‘s|^set -e|#set -e|g’ $i ; done

    (but depending on the package you might need to use ‘s|#/bin/sh -e|#/bin/sh|g’ — as stated in the first post)

    You may want to have a backup of these files in some folder to restore them if something goes wrong, before doing that.

  6. I mean, I don’t know *how many* of these files have to be edited, sorry. In my case there were at least about 6 of them (according with the post, I didn’t bother to check to see if each one of them had the -e option), so doing it all with a command for backup and another to editing it all makes everything a bit faster.

  7. [email protected]:~$

    [email protected]:~$ cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=9.10
    DISTRIB_CODENAME=karmic
    DISTRIB_DESCRIPTION="Ubuntu 9.10"
    [email protected]:~$ uname -a
    Linux mary-laptop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
    [email protected]:~$ cat /etc/lsb-releaseuname -a
    cat: invalid option -- 'a'
    Try `cat --help' for more information.
    [email protected]:~$ cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=9.10
    DISTRIB_CODENAME=karmic
    DISTRIB_DESCRIPTION="Ubuntu 9.10"
    [email protected]:~$
    [email protected]:~$ uname -a
    Linux mary-laptop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
    [email protected]:~$
    [email protected]:~$ sudo rm /var/lib/apt/lists/lock
    [sudo] password for mary:
    Sorry, try again.
    [sudo] password for mary:
    [email protected]:~$ cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=9.10
    DISTRIB_CODENAME=karmic
    DISTRIB_DESCRIPTION="Ubuntu 9.10"
    [email protected]:~$
    [email protected]:~$ uname -a
    Linux mary-laptop 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64 GNU/Linux
    [email protected]:~$
    [email protected]:~$ sudo rm /var/lib/apt/lists/lock
    rm: cannot remove `/var/lib/apt/lists/lock': No such file or directory
    [email protected]:~$
    [email protected]:~$ sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup
    
    
    
    
    
    [email protected]:~$
    [email protected]:~$ sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status
    [email protected]:~$
    [email protected]:~$ sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available
    [email protected]:~$
    [email protected]:~$ sudo rm -rf /var/lib/dpkg/updates/*
    [email protected]:~$
    [email protected]:~$ sudo rm -rf /var/lib/apt/lists
    [email protected]:~$
    [email protected]:~$ sudo mkdir /var/lib/apt/lists
    [email protected]:~$
    [email protected]:~$ sudo mkdir /var/lib/apt/lists/partial
    [email protected]:~$
    [email protected]:~$ sudo rm /var/cache/apt/*.bin
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get clean
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get autoclean
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get --purge autoremove
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: The package linux-image-2.6.31-22-generic needs to be reinstalled, but I can't find an archive for it.
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824
    Get:1 http://us.archive.ubuntu.com lucid Release.gpg [189B]
    Get:2 http://us.archive.ubuntu.com lucid-updates Release.gpg [198B]
    Get:3 http://us.archive.ubuntu.com lucid Release [57.2kB]
    Get:4 http://archive.canonical.com karmic Release.gpg [198B]
    Get:5 http://security.ubuntu.com lucid-security Release.gpg [198B]
    Get:6 http://archive.canonical.com karmic Release [9359B]
    Get:7 http://security.ubuntu.com lucid-security Release [38.5kB]
    Get:8 http://us.archive.ubuntu.com lucid-updates Release [44.7kB]
    Get:9 http://archive.canonical.com karmic/partner Packages [3906B]
    Get:10 http://us.archive.ubuntu.com lucid/main Packages [1383kB]
    Get:11 http://security.ubuntu.com lucid-security/main Packages [96.7kB]
    Get:12 http://security.ubuntu.com lucid-security/restricted Packages [14B]
    Get:13 http://security.ubuntu.com lucid-security/main Sources [34.8kB]
    Get:14 http://security.ubuntu.com lucid-security/restricted Sources [14B]
    Get:15 http://security.ubuntu.com lucid-security/universe Packages [48.2kB]
    Get:16 http://security.ubuntu.com lucid-security/universe Sources [12.9kB]
    Get:17 http://security.ubuntu.com lucid-security/multiverse Packages [1875B]
    Get:18 http://security.ubuntu.com lucid-security/multiverse Sources [655B]
    Get:19 http://us.archive.ubuntu.com lucid/restricted Packages [6193B]
    Get:20 http://us.archive.ubuntu.com lucid/main Sources [659kB]
    Get:21 http://us.archive.ubuntu.com lucid/restricted Sources [3775B]
    Get:22 http://us.archive.ubuntu.com lucid/universe Packages [5430kB]
    Get:23 http://us.archive.ubuntu.com lucid/universe Sources [3165kB]
    Get:24 http://us.archive.ubuntu.com lucid/multiverse Packages [176kB]
    Get:25 http://us.archive.ubuntu.com lucid/multiverse Sources [119kB]
    Get:26 http://us.archive.ubuntu.com lucid-updates/main Packages [342kB]
    Get:27 http://us.archive.ubuntu.com lucid-updates/restricted Packages [3267B]
    Get:28 http://us.archive.ubuntu.com lucid-updates/main Sources [133kB]
    Get:29 http://us.archive.ubuntu.com lucid-updates/restricted Sources [1443B]
    Get:30 http://us.archive.ubuntu.com lucid-updates/universe Packages [146kB]
    Get:31 http://us.archive.ubuntu.com lucid-updates/universe Sources [56.7kB]
    Get:32 http://us.archive.ubuntu.com lucid-updates/multiverse Packages [7312B]
    Get:33 http://us.archive.ubuntu.com lucid-updates/multiverse Sources [3669B]
    Fetched 12.0MB in 19s (612kB/s)
    Reading package lists... Done
    [email protected]:~$
    [email protected]:~$ sudo dpkg --clear-avail
    [email protected]:~$
    [email protected]:~$ sudo dpkg --configure -a
    Setting up libfreetype6 (2.3.9-5ubuntu0.4) ...
    
    Setting up libxml2 (2.7.5.dfsg-1ubuntu1.1) ...
    
    Processing triggers for man-db ...
    Processing triggers for sreadahead ...
    Setting up cpp-4.4 (4.4.1-4ubuntu9) ...
    Setting up libc-dev-bin (2.10.1-0ubuntu18) ...
    Processing triggers for software-center ...
    Processing triggers for doc-base ...
    Setting up linux-libc-dev (2.6.31-22.68) ...
    Setting up adduser (3.110ubuntu7) ...
    
    Setting up cups-common (1.4.1-5ubuntu2.7) ...
    Setting up libtiff4 (3.8.2-13ubuntu0.3) ...
    
    Setting up libkrb5support0 (1.7dfsg~beta3-1ubuntu0.6) ...
    
    Setting up x11-common (1:7.4+3ubuntu10) ...
    
    Processing triggers for ufw ...
    Setting up libavahi-common-data (0.6.25-1ubuntu5.2) ...
    Setting up libavahi-common3 (0.6.25-1ubuntu5.2) ...
    
    Setting up libbz2-1.0 (1.0.5-3ubuntu0.1) ...
    
    Setting up libavahi-client3 (0.6.25-1ubuntu5.2) ...
    
    Setting up libldap-2.4-2 (2.4.18-0ubuntu1.1) ...
    
    Setting up libpng12-0 (1.2.37-1ubuntu0.2) ...
    
    Setting up binutils (2.20-0ubuntu2) ...
    
    Setting up libgomp1 (4.4.1-4ubuntu9) ...
    
    Setting up libc6-dev (2.10.1-0ubuntu18) ...
    Setting up bzip2 (1.0.5-3ubuntu0.1) ...
    
    Setting up libk5crypto3 (1.7dfsg~beta3-1ubuntu0.6) ...
    
    Setting up gcc-4.4 (4.4.1-4ubuntu9) ...
    Setting up python2.6 (2.6.4-0ubuntu3) ...
    
    Setting up libpoppler5 (0.12.0-0ubuntu2.3) ...
    
    Setting up poppler-utils (0.12.0-0ubuntu2.3) ...
    Setting up libkrb5-3 (1.7dfsg~beta3-1ubuntu0.6) ...
    
    Setting up libgssapi-krb5-2 (1.7dfsg~beta3-1ubuntu0.6) ...
    
    Setting up libpython2.6 (2.6.4-0ubuntu3) ...
    
    Setting up python (2.6.4-0ubuntu1) ...
    
    Setting up libcups2 (1.4.1-5ubuntu2.7) ...
    
    Setting up libcupscgi1 (1.4.1-5ubuntu2.7) ...
    
    Setting up libcupsppdc1 (1.4.1-5ubuntu2.7) ...
    
    Setting up libcupsimage2 (1.4.1-5ubuntu2.7) ...
    
    Setting up cups-client (1.4.1-5ubuntu2.7) ...
    
    Setting up libcupsmime1 (1.4.1-5ubuntu2.7) ...
    
    Setting up libcupsdriver1 (1.4.1-5ubuntu2.7) ...
    
    Setting up libgs8 (8.70.dfsg.1-0ubuntu3.1) ...
    
    Setting up foomatic-filters (4.0.3-0ubuntu2.2) ...
    
    Setting up ghostscript (8.70.dfsg.1-0ubuntu3.1) ...
    Updating font configuration of gs...
    Cleaning up category psprint..
    Cleaning up category cmap..
    Cleaning up category cid..
    Cleaning up category truetype..
    Cleaning up category gsfontderivative..
    Cleaning up category type3..
    Cleaning up category type1..
    Updating category type1..
    Updating category type3..
    Updating category gsfontderivative..
    Updating category truetype..
    Updating category cid..
    Updating category cmap..
    Updating category psprint..
    No CIDSupplement specified for ZenHei, defaulting to 0.
    No CIDSupplement specified for Dotum-Bold, defaulting to 0.
    No CIDSupplement specified for Dotum-Regular, defaulting to 0.
    No CIDSupplement specified for Batang-Regular, defaulting to 0.
    No CIDSupplement specified for ZenHei-CNS, defaulting to 0.
    No CIDSupplement specified for Batang-Bold, defaulting to 0.
    
    Setting up cups-bsd (1.4.1-5ubuntu2.7) ...
    
    Setting up cups (1.4.1-5ubuntu2.7) ...
     * Starting Common Unix Printing System: cupsd                           [ OK ]
    
    Setting up language-pack-en (1:9.10+20100604) ...
    Setting up language-pack-en-base (1:9.10+20100604) ...
    Generating locales...
      en_AG.UTF-8... up-to-date
      en_AU.UTF-8... up-to-date
      en_BW.UTF-8... up-to-date
      en_CA.UTF-8... up-to-date
      en_DK.UTF-8... up-to-date
      en_GB.UTF-8... up-to-date
      en_HK.UTF-8... up-to-date
      en_IE.UTF-8... up-to-date
      en_IN.UTF-8... up-to-date
      en_NG.UTF-8... up-to-date
      en_NZ.UTF-8... up-to-date
      en_PH.UTF-8... up-to-date
      en_SG.UTF-8... up-to-date
      en_US.UTF-8... up-to-date
      en_ZA.UTF-8... up-to-date
      en_ZW.UTF-8... up-to-date
    Generation complete.
    
    Setting up language-pack-gnome-en (1:9.10+20100604.2) ...
    Setting up language-pack-gnome-en-base (1:9.10+20100604.2) ...
    
    Processing triggers for libc-bin ...
    ldconfig deferred processing now taking place
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get -f install
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: The package linux-image-2.6.31-22-generic needs to be reinstalled, but I can't find an archive for it.
    [email protected]:~$
    [email protected]:~$ LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824 && sudo apt-get dist-upgrade
    Hit http://archive.canonical.com karmic Release.gpg
    Hit http://us.archive.ubuntu.com lucid Release.gpg
    Hit http://us.archive.ubuntu.com lucid-updates Release.gpg
    Hit http://archive.canonical.com karmic Release
    Hit http://us.archive.ubuntu.com lucid Release
    Hit http://security.ubuntu.com lucid-security Release.gpg
    Hit http://archive.canonical.com karmic/partner Packages
    Hit http://us.archive.ubuntu.com lucid-updates Release
    Hit http://security.ubuntu.com lucid-security Release
    Hit http://us.archive.ubuntu.com lucid/main Packages
    Hit http://us.archive.ubuntu.com lucid/restricted Packages
    Hit http://us.archive.ubuntu.com lucid/main Sources
    Hit http://security.ubuntu.com lucid-security/main Packages
    Hit http://us.archive.ubuntu.com lucid/restricted Sources
    Hit http://us.archive.ubuntu.com lucid/universe Packages
    Hit http://us.archive.ubuntu.com lucid/universe Sources
    Hit http://us.archive.ubuntu.com lucid/multiverse Packages
    Hit http://us.archive.ubuntu.com lucid/multiverse Sources
    Hit http://us.archive.ubuntu.com lucid-updates/main Packages
    Hit http://us.archive.ubuntu.com lucid-updates/restricted Packages
    Hit http://security.ubuntu.com lucid-security/restricted Packages
    Hit http://security.ubuntu.com lucid-security/main Sources
    Hit http://us.archive.ubuntu.com lucid-updates/main Sources
    Hit http://us.archive.ubuntu.com lucid-updates/restricted Sources
    Hit http://us.archive.ubuntu.com lucid-updates/universe Packages
    Hit http://us.archive.ubuntu.com lucid-updates/universe Sources
    Hit http://us.archive.ubuntu.com lucid-updates/multiverse Packages
    Hit http://us.archive.ubuntu.com lucid-updates/multiverse Sources
    Hit http://security.ubuntu.com lucid-security/restricted Sources
    Hit http://security.ubuntu.com lucid-security/universe Packages
    Hit http://security.ubuntu.com lucid-security/universe Sources
    Hit http://security.ubuntu.com lucid-security/multiverse Packages
    Hit http://security.ubuntu.com lucid-security/multiverse Sources
    Reading package lists... Done
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: The package linux-image-2.6.31-22-generic needs to be reinstalled, but I can't find an archive for it.
    

    [email protected]:~$
    [email protected]:~$
    [email protected]:~$
    [email protected]:~$
    [email protected]:~$

  8. As with #4 Feudjay & #7 Ruud I did not have “#/bin/sh -e” in any of my package scripts.
    I too had “set -e”, but it turns out simply deleting the “-e” at the end of “set -e” made it all worked like a charm.

  9. Hi, I have the same problem with Kubuntu, every time am trying to update it from the “Update System” I get that error and it will not allow me to do it, please any help in that?

Leave a Comment