[SOLVED] “subprocess pre-removal script returned error exit status 2” error

[ad#ad-1] Recently, I encountered a package management related error in Ubuntu Jaunty Jackalope 64bit.

The package was python-beagle and the error was: “E: python-beagle: subprocess pre-removal script returned error exit status 2” and details showed:

dpkg (subprocess): unable to execute pre-removal script: Exec format error
dpkg: error processing python-beagle (–remove):
subprocess pre-removal script returned error exit status 2
dpkg (subprocess): unable to execute post-installation script: Exec format error
dpkg: error while cleaning up:
subprocess post-installation script returned error exit status 2
Errors were encountered while processing:
python-beagle
E: Sub-process /usr/bin/dpkg returned an error code (1)

I managed to fix it. Read on for how I did it.

Precaution: The process can break your system if not followed as mentioned (you may get into problems even if you follow the process). Please proceed at your own risk.

First, please try the following in terminal:

sudo aptitude update
sudo aptitude -f install

If it does not work, then you may want to try:

sudo dpkg --force all --remove

If both of them still produce similar errors, then continue. If the above commands fix your problem, you should not continue.

1. Close Synaptic or any package manager. Wait for or cancel any updates or installuninstall.
2. Make Backups of current /var/lib/dpkg/status file. Just copy and paste to your home directory or Desktop.
3. Alt+F2 and launch type in gksu gedit /var/lib/dpkg/status and run it. Gedit will be launched with a text file open.
4. Now, search for the exact name of the package with problems and find it.
5. In my case, it I found the entry for the package python-beagle:

Package: python-beagle
Status: deinstall ok half-configured
Priority: optional
Section: python
Installed-Size: 168
Maintainer: Ubuntu Core Developers
Architecture: amd64
Source: libbeagle
Version: 0.3.5-2build1
Replaces: python2.4-beagle (<< 0.2.7-1)
Provides: python2.6-beagle
Depends: python (<< 2.7), python (>= 2.6), python-support (>= 0.7.1), libbeagle1 (>= 0.3.5), libc6 (>= 2.4), python-gtk2
Conflicts: python2.4-beagle (<< 0.2.7-1)
Description: Python bindings for beagle
Allow accessing Beagle daemon and peforming searches using Python.

6. Select and delete that information and that much information only, i.e. you will remove “Package: culprit-package-name” to “Description: culprit package description”. Remmber, “culprit package description” may be multiline and you will need to remove all the lines till a blank line. Don’t forget to leave a line blank between the package description above and the one below. To clarify things out, I have placed the images here, pelase have a look. Here the package to be removed is python-beagle.

Before Deletion
Before Deletion
Selection
Selection
After
After

7. Launch Synaptic (or any package manager) and then search for package. You will see the package as not installed. Mark it for installation and install it. If you start to see the same error, restart the same process from Step 1 but the next time, stop at step 6.
8. Now, you should be able to remove it if you no longer want the package. If you can’t, restart the same process from Step 1 but the next time, stop at step 6.

Hope this was helpful. Please post in comments.

  • Thanks a lot for your sharing, it saved me a hour encountering a similar problem in Ubuntu.

  • Weevil

    Got the fakeroot package permanently half-installed when my laptop battery ran out during upgrade. Thanks to your blogpost it finally got fixed!

  • Thanks for putting this out there. It’s a shame dpkg doesn’t have a more graceful way of showing its displeasure.

  • Pingback: How to Fix โ€œsubprocess pre-removal script returned error exit status 2โ€ณ Error « Odzangba Kafui Dake’s Blog()

  • name

    wow, you rock dude.
    thanks

  • ubu-solved

    Thanks, it help me very much. After 6-th step I downloaded the jaunty package – installed – and after all uninstalled. It worked!

  • Eleven

    thx alots .. this post is really helpful for me .. again .. thanks so much ๐Ÿ™‚

  • che

    Thanks dude,
    searched hours for a damned solution and found your blog which helped. In my case it was the vim-gnome package due to a hardware crash during the installation.

  • Eek. That’s rather an over-the-top appreach. Better solution is to edit /var/lib/dpkg/info/packagename.prerm and comment out the offending lines (you can see what that script does, and do things by hand, if it’s failing)

  • ethnopunk

    In my case it was a lifesaver. Difference between having a slightl broken system and a totally broken system

    http://ubuntuforums.org/showthread.php?t=1348866

    Removing the -e flag in the prerm didn’t work.It keeps returning because of policy on the system. The hack is not ideal. A solution would be better.

  • demon_edge

    Thanks.. This help my problems.
    I’m from Indonesia, sorry I can’t speak English very well ๐Ÿ˜€

  • Manuel

    Thanks for sharing it!!

  • Ed Welbon

    Thanks for the tip. I fixed the problem in vim with following change command

    :%s/Package:.*\nStatus:.*half-.*\(\n$\)*//

    The trick is to treat the file like one long string and find problematic package paragraph by looking for the portion of the file that contains the string “half-” where the string is preceded by Package: and followed eventually by a blank line. Having found that portion, replace it with nothing. It harder to explain than do ๐Ÿ™‚ A good way to be sure that it works is compare the changed file with a backup of the original file using vim “split diff with …” under the edit tab. I’ve been using vi/vim for 15 years and it still amazes me. It’s much better than beer ๐Ÿ™‚

  • Thanks a lot. You saved my lots of efforts.

  • Danish

    Hi this is one page that i will save for eternity.. ๐Ÿ˜‰ Thank you very much. It was really irritating to see the errors everytime i installed anything.

  • Pingback: [SOLVED] Unable to get Exclusive Lock Problem While Launching Synaptic, /var/lib/dpkg/lock - open (11 Resource temporarily unavailable) Error | The _khAttAm_ blog()

  • Thanks a ton! In my case, hddtemp got stuck in limbo when (ironically enough) my computer overheated and shut down during installation of sensors-applet. Now everything’s set up correctly.

  • Robert Keane

    A powerful thanks. dpkg s/b more verbose, glad you are.

  • Thanks man …. you have just saved me ๐Ÿ˜€

  • thomas

    you just saved a re-installation. thank you much kind sir.

  • Thanks buddy by following only step 6 I was able to resolve my screelets problem.

    Thanks again

  • Skyler

    Thank you very much for the information. Helped me fix a problem I had with compizconfig-settings-manager ๐Ÿ™‚ .

    The last step worked.

  • Luka

    Great, it worked!
    Thanks for sharing!

  • Worked like a charm !! ๐Ÿ™‚
    Thanks for the wonderful work !

  • dingbat

    Thanks, simple and efficient.

  • nrao

    worked for me too ๐Ÿ™‚

    thanks.

  • potam

    Thanks man,
    This fixed my fglrx ati radeon problem, which crashed after upgrade to ubuntu 10.04. After doing the first two steps, I was able to re-install the proprietary driver, re-booted, and the graphics resolution was back.

  • kralizec

    Thanks for this! I’d been searching for a fix to this problem with package libruby1.8 in Lucid for quite some time and this finally worked!

  • jef

    thanks heaps! very useful indeed

  • howell

    thank you!

  • Mike Munsil

    THANK YOU! this was driving me (even more) batty.

  • Thanks I have had one package that I could not remove. First time in years that it happened.

    Ken.

  • Pingback: how to remove a package which post-installation and pre-removal script fails?()

  • H U I L E Z

    I was suffering from this same error. but with different packages.

    It was all caused by having 2 mouses on the same computer.

    removed the second mouse. problems instantly fixed

  • guest

    thanks for your help :DDDD

  • Vittorio

    pure gold, thanks!

  • Piyush Kumar

    Thanks, worked for me ๐Ÿ˜€

  • Rick

    Saved my butt. NICE ONE.

  • Venkatesh

    You are awesome man!!

  • J2boychuk

    that saved me from a new install thanks a lot, clear explicit solution instead of the usual vague 1/2 intelligible theory crap so often found for solutions.
    as many posts show below, you are the man ! !

    thanks

    jack

  • Seraphtrend

    Awsome! worked – only after i noticed that i had to change this
    “3. Alt+F2 and launch type in gksu gedit /var/lib/dpkg/status and run it. Gedit will be launched with a text file open.”
    instead of “gedit” i have to use geany which is MY text editor.
    thanks for posting this solution!ย 

  • Me

    God bless you…work like magic

  • Edy junaidi

    thanks for the solution, it solved my problems after googling for almost an hour

  • Zaq1xsw2

    This post saved the day. ย Sigh of relief. ย Thanks!

  • Wim De Winter

    Thanks a lot. This solution worked!

    Thanks!

  • mf

    awesome, you saved my day!
    thank you very much

  • bahha

    Thanks a lot

  • Pingback: inQuest - Basic software required in backtrack or linux must for all ..()

  • Dragan

    Thanks

  • Phil Headford

    Thank you to 49. I had a stuck half-install of Python3: followed the general method given, and achieved a clean install.