Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I went to install bsnes the other day and for whatever reason the installation failed. Now, I cannot update, install new packages, or do basically any apt-get commands as they all try to process this broken package and fail. Attempting to install a new package also just dooms it to the same fate. The error I get is:

Setting up google-chrome-stable (33.0.1750.152-1) ...
/var/lib/dpkg/info/google-chrome-stable.postinst: 124: /var/lib/dpkg/info/google-chrome-stable.postinst: update-alternatives: not found
dpkg: error processing google-chrome-stable (--configure):
 subprocess installed post-installation script returned error exit status 127
Setting up bsnes (0.088-7) ...
/var/lib/dpkg/info/bsnes.postinst: 5: /var/lib/dpkg/info/bsnes.postinst: update-alternatives: not found
dpkg: error processing bsnes (--configure):
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have been searching on Google and here on Ask Ubuntu but have not found a working solution. The commonly suggested fix is to run the following:

sudo apt-get clean && sudo apt-get autoremove
sudo apt-get -f install
sudo dpkg --configure -a

This however does not work. The apt-get commands all fail with the same error as above and the dpkg command just doesn't help. The other thing they often suggest to purge it via Synaptic or the command line, which also fails.

Thanks for the help

share|improve this question

Other than those which you have already posted, there are few other commands which can be helpful.

  • Autoclean clears out the local repository of retrieved package files.

    sudo apt-get autoclean
  • Force installation/removal of packages. ☠Use with caution

    sudo apt-get --force-yes install <pkgname>


    sudo apt-get --force-yes remove <pkgname>

Also as always, you can use dpkg to install, remove and purge packages.

  • Install

    sudo dpkg -i <pkgname>
  • Remove

    sudo dpkg -r <pkgname>
  • Purge

    sudo dpkg -P <pkgname>
share|improve this answer
Both dpkg and the apt-get --force-yes commands return the same error as I was getting before. Autoclean doesn't return an error but also doesn't seem to do anything with the two broken packages. – Bijak Mar 24 '14 at 4:22
@Bijak You must have surely tried purging bsnes .Have you? – Registered User Mar 24 '14 at 4:26
Yep, with dpkg -P, apt-get purge, and with Synaptic – Bijak Mar 24 '14 at 12:39
Post the output of dpkg -l |grep bsnes – Registered User Mar 24 '14 at 12:51
rF bsnes 0.088-7 amd64 Accurate SNES/SuperFamicom emulator – Bijak Mar 24 '14 at 13:09

For advanced users, use at your own risks.

According to the following error message :

subprocess installed post-installation script returned error exit status 127

You may want to edit /var/lib/dpkg/info/[package_name].postinst and comment everything (or better yet, try to understand it and identify the issue), then try apt-get again.

Note that though in this particular question the message concerns "post-installation", it could have mentioned e.g. "pre-removal" or "post-removal" instead (in which cases the extension of the file to be edited would have been .prerm or .postrm).

share|improve this answer
Actually this is the best method. Reinstalling dpkg doesn't always help. – Danatela Dec 24 '15 at 10:36
Thanks heaps. I had to fix /var/lib/dpkg/info/[package_name].prerm but your post gave me the right direction. Definitely for advanced users though, this is risky! – sмurf Jan 6 at 23:10
Give this man a metal! That works great thanks! – Lance Badger Jul 14 at 15:10
up vote 3 down vote accepted

So, after more googling and really carefully reading through the error messages again it seems that dpkg needed to be reinstalled.

sudo apt-get install --reinstall dpkg

What tipped off that this was the problem (if anyone searches and sees this) is that update-alternatives: not found was in the error message. As soon as dpkg was reinstalled, the other packages proceeded to install normally automatically.

share|improve this answer

If all else fails, you can manually remove the package through dpkg. Running sudo dpkg -P bsnes should purge bsnes.

share|improve this answer

If all else fails. What I did was I first changed the directory to:

cd /var/lib/dpkg/info

then I removed everything with .postinst:

rm *.postinst

then everything went back to normal when I did:

apt-get --force-yes install openjdk-7-jre-headless
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.