125

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.

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
Bijak
  • 1,679

11 Answers11

109

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

67

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>
    

    and

    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>
    
54

You can remove the package file in this /var/lib/dpkg/info/ path and update the source.

sudo rm /var/lib/dpkg/info/[package_name].*
sudo dpkg --configure -a
sudo apt-get update

Then, reinstall your package sudo apt-get install [package_name]

Doc

Benyamin Jafari
  • 4,234
  • 4
  • 27
  • 37
Hamed
  • 820
  • 9
  • 12
32

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.

Bijak
  • 1,679
19

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:

sudo rm *.postinst

then update repository

sudo apt-get update

then everything went back to normal when I did:

sudo apt-get --force-yes install openjdk-7-jre-headless
Zanna
  • 72,312
Mike B
  • 331
4

Try this:

sudo dpkg -l | grep '^.[^i]'

Then for each packages which have something other than ii in the first and second column, or an ..R in the third column, remove them using:

sudo dpkg --remove --force-all package_name  ## You might need to do this a lot
sudo apt-get clean
sudo apt-get update
sudo apt-get --fix-broken install
sudo apt-get autoremove

Hopefully, this should fix it.

rusty
  • 16,917
4

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

saiarcot895
  • 10,917
4

In my case apt-get install -f worked. I was installing mysql-workbench-community

Previously tried apt autoclean

I saw that dpkg error due to some missing dependencies which could be corrected by installing in forced mode( installing dependencies)

Vikas Avnish
  • 141
  • 1
3

I had a similar situation with multiple packages that weren't fully installed and I didn't know what they were. To fix it I followed this answer: https://unix.stackexchange.com/a/114193

The steps were:

  1. use sudo dpkg -C to get the list of all the packages that are in an incomplete state of installation.
  2. Edit the list it provides so that it's only 1 line of just the package names.
  3. run sudo dpkg --configure [list of packages separated by spaces] on all those packages.
  4. run sudo dpkg --configure --pending to catch the few packages for which step #3 was insufficient.

However, I do wonder if perhaps step #4 is the only step that's actually needed, or perhaps sudo dpkg --configure -a && sudo dpkg --configure --pending was the single line that would have done the trick. In any case, the 4 steps above solved the problem for me.

1
sudo apt-get install -f --reinstall coreutils init-system-helpers

After running above, you can install/upgrade/remove/purge as usual for any packages.

0

To remove it, just run:

sudo apt --fix-broken install

To install it, I would try downloading the DEB file. So, without breaking APT (raising the error "E: Unmet dependencies. Try 'apt --fix-broken install" with no packages (or specify a solution)") and without installing the dependencies (imagine you downloaded a .deb and some dependency is not in the APT repos anymore, my case), the only option I could find it works is the following one:

Imagine say you downloaded the DEB package from the publisher site, let's say provided-deb-package-name.deb, and mocking the unexisting package (while the publisher does not provide a version), let's call it unexisting-package-name:

sudo apt install equivs
equivs-control unexisting-package-name
vim unexisting-package-name  # check below the content and changes
equivs-build unexisting-package-name
sudo dpkg -i unexisting-package-name.deb
sudo dpkg -i provided-deb-package-name.deb
sudo apt upgrade # this worked

unexisting-package-name content:

### Commented entries have reasonable defaults.
### Uncomment to edit them.
# Source: <source package name; defaults to package name>
Section: misc
Priority: optional
# Homepage: <enter URL here; no default>
Standards-Version: 3.9.2

Package: unexisting-package-name

...

Provides: missing-package

...

Description: SomeCompn Robotics unexisting-package-name unpublished package, required to simulate their robots.

I know the solution is maybe not the most elegant, but it works and it's temporary after all.

xCovelus
  • 301