Ubuntu – How to remove/install a package that is not fully installed

aptitudedpkgpackage-management

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:
 google-chrome-stable
 bsnes
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.

Best Answer

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).

Related Question