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











up vote
49
down vote

favorite
22












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.



Thanks for the help










share|improve this question


























    up vote
    49
    down vote

    favorite
    22












    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.



    Thanks for the help










    share|improve this question
























      up vote
      49
      down vote

      favorite
      22









      up vote
      49
      down vote

      favorite
      22






      22





      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.



      Thanks for the help










      share|improve this question













      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.



      Thanks for the help







      package-management dpkg aptitude






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 '14 at 2:42









      Bijak

      586147




      586147






















          8 Answers
          8






          active

          oldest

          votes

















          up vote
          50
          down vote













          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

















          • 2




            Actually this is the best method. Reinstalling dpkg doesn't always help.
            – Danatela
            Dec 24 '15 at 10:36






          • 2




            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 '16 at 23:10










          • The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
            – fuser
            May 27 '17 at 9:28


















          up vote
          38
          down vote













          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>







          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


















          up vote
          24
          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

















          • 3




            Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
            – David Foerster
            Mar 31 '17 at 23:02












          • for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
            – Joe
            May 19 '17 at 20:13








          • 2




            This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
            – michael
            May 26 '17 at 16:04


















          up vote
          12
          down vote













          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





          share|improve this answer



















          • 6




            This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
            – David Foerster
            Mar 31 '17 at 22:57












          • If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
            – Ian Mackinnon
            Jan 6 at 12:47












          • after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
            – Andy
            Apr 9 at 20:00


















          up vote
          10
          down vote













          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






          share|improve this answer



















          • 3




            Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
            – smac89
            Jun 21 '17 at 16:28


















          up vote
          5
          down vote













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






          share|improve this answer

















          • 2




            dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
            – endolith
            Nov 14 '16 at 5:27


















          up vote
          2
          down vote













          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)






          share|improve this answer






























            up vote
            0
            down vote













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


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






            share|improve this answer




















              protected by Community Oct 1 '17 at 19:25



              Thank you for your interest in this question.
              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



              Would you like to answer one of these unanswered questions instead?














              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              50
              down vote













              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

















              • 2




                Actually this is the best method. Reinstalling dpkg doesn't always help.
                – Danatela
                Dec 24 '15 at 10:36






              • 2




                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 '16 at 23:10










              • The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
                – fuser
                May 27 '17 at 9:28















              up vote
              50
              down vote













              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

















              • 2




                Actually this is the best method. Reinstalling dpkg doesn't always help.
                – Danatela
                Dec 24 '15 at 10:36






              • 2




                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 '16 at 23:10










              • The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
                – fuser
                May 27 '17 at 9:28













              up vote
              50
              down vote










              up vote
              50
              down vote









              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












              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












              share|improve this answer



              share|improve this answer










              answered Jun 5 '15 at 7:58









              Skippy le Grand Gourou

              1,2341917




              1,2341917








              • 2




                Actually this is the best method. Reinstalling dpkg doesn't always help.
                – Danatela
                Dec 24 '15 at 10:36






              • 2




                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 '16 at 23:10










              • The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
                – fuser
                May 27 '17 at 9:28














              • 2




                Actually this is the best method. Reinstalling dpkg doesn't always help.
                – Danatela
                Dec 24 '15 at 10:36






              • 2




                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 '16 at 23:10










              • The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
                – fuser
                May 27 '17 at 9:28








              2




              2




              Actually this is the best method. Reinstalling dpkg doesn't always help.
              – Danatela
              Dec 24 '15 at 10:36




              Actually this is the best method. Reinstalling dpkg doesn't always help.
              – Danatela
              Dec 24 '15 at 10:36




              2




              2




              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 '16 at 23:10




              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 '16 at 23:10












              The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
              – fuser
              May 27 '17 at 9:28




              The best answer. Thanks! Correcting .prerm and .postrm files fix the problem.
              – fuser
              May 27 '17 at 9:28












              up vote
              38
              down vote













              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>







              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















              up vote
              38
              down vote













              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>







              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













              up vote
              38
              down vote










              up vote
              38
              down vote









              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>







              share|improve this answer












              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>








              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 24 '14 at 4:10









              Registered User

              5,912114170




              5,912114170












              • 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


















              • 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
















              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




              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




              @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




              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




              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




              rF bsnes 0.088-7 amd64 Accurate SNES/SuperFamicom emulator
              – Bijak
              Mar 24 '14 at 13:09










              up vote
              24
              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

















              • 3




                Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
                – David Foerster
                Mar 31 '17 at 23:02












              • for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
                – Joe
                May 19 '17 at 20:13








              • 2




                This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
                – michael
                May 26 '17 at 16:04















              up vote
              24
              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

















              • 3




                Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
                – David Foerster
                Mar 31 '17 at 23:02












              • for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
                – Joe
                May 19 '17 at 20:13








              • 2




                This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
                – michael
                May 26 '17 at 16:04













              up vote
              24
              down vote



              accepted







              up vote
              24
              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












              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












              share|improve this answer



              share|improve this answer










              answered Mar 25 '14 at 3:26









              Bijak

              586147




              586147








              • 3




                Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
                – David Foerster
                Mar 31 '17 at 23:02












              • for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
                – Joe
                May 19 '17 at 20:13








              • 2




                This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
                – michael
                May 26 '17 at 16:04














              • 3




                Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
                – David Foerster
                Mar 31 '17 at 23:02












              • for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
                – Joe
                May 19 '17 at 20:13








              • 2




                This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
                – michael
                May 26 '17 at 16:04








              3




              3




              Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
              – David Foerster
              Mar 31 '17 at 23:02






              Why is the only correct (and accepted) answer so far down the list with less than ⅓ of the votes of the top answer? +1
              – David Foerster
              Mar 31 '17 at 23:02














              for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
              – Joe
              May 19 '17 at 20:13






              for one: because it doesn't work for packages which can no longer be downloaded "Reinstallation of linux-image-extra-4.4.0-65-generic is not possible, it cannot be downloaded."
              – Joe
              May 19 '17 at 20:13






              2




              2




              This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
              – michael
              May 26 '17 at 16:04




              This is probably the least likely solution for anyone coming here based on the title of the question. But there are a lot of reasons one can end up with this problem, so there will be a lot of proposed "this works for me" solutions.
              – michael
              May 26 '17 at 16:04










              up vote
              12
              down vote













              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





              share|improve this answer



















              • 6




                This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
                – David Foerster
                Mar 31 '17 at 22:57












              • If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
                – Ian Mackinnon
                Jan 6 at 12:47












              • after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
                – Andy
                Apr 9 at 20:00















              up vote
              12
              down vote













              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





              share|improve this answer



















              • 6




                This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
                – David Foerster
                Mar 31 '17 at 22:57












              • If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
                – Ian Mackinnon
                Jan 6 at 12:47












              • after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
                – Andy
                Apr 9 at 20:00













              up vote
              12
              down vote










              up vote
              12
              down vote









              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





              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:



              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






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 28 '17 at 19:48









              Zanna

              49.2k13123234




              49.2k13123234










              answered Apr 14 '16 at 2:39









              Mike B

              13714




              13714








              • 6




                This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
                – David Foerster
                Mar 31 '17 at 22:57












              • If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
                – Ian Mackinnon
                Jan 6 at 12:47












              • after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
                – Andy
                Apr 9 at 20:00














              • 6




                This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
                – David Foerster
                Mar 31 '17 at 22:57












              • If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
                – Ian Mackinnon
                Jan 6 at 12:47












              • after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
                – Andy
                Apr 9 at 20:00








              6




              6




              This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
              – David Foerster
              Mar 31 '17 at 22:57






              This removes all post-installation scripts not just that of the affected package. A bit too overzealous in my opinion. -1
              – David Foerster
              Mar 31 '17 at 22:57














              If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
              – Ian Mackinnon
              Jan 6 at 12:47






              If it's easy to identify and remove only the particular post-install script causing a problem this can be a very convenient way to remove a failing package.
              – Ian Mackinnon
              Jan 6 at 12:47














              after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
              – Andy
              Apr 9 at 20:00




              after a nightmare with kernal issues renaming the .postinst of just the affected kernel fixed the issue
              – Andy
              Apr 9 at 20:00










              up vote
              10
              down vote













              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






              share|improve this answer



















              • 3




                Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
                – smac89
                Jun 21 '17 at 16:28















              up vote
              10
              down vote













              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






              share|improve this answer



















              • 3




                Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
                – smac89
                Jun 21 '17 at 16:28













              up vote
              10
              down vote










              up vote
              10
              down vote









              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






              share|improve this answer














              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







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 30 at 3:09









              Benyamin Jafari

              25314




              25314










              answered May 30 '17 at 8:29









              Hamed

              16217




              16217








              • 3




                Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
                – smac89
                Jun 21 '17 at 16:28














              • 3




                Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
                – smac89
                Jun 21 '17 at 16:28








              3




              3




              Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
              – smac89
              Jun 21 '17 at 16:28




              Actually you had better use sudo rm /var/lib/dpkg/info/[pakege_name].*. Otherwise you will also remove packages that start with the same name. Anyways, thanks for this, it was the only solution that worked for me
              – smac89
              Jun 21 '17 at 16:28










              up vote
              5
              down vote













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






              share|improve this answer

















              • 2




                dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
                – endolith
                Nov 14 '16 at 5:27















              up vote
              5
              down vote













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






              share|improve this answer

















              • 2




                dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
                – endolith
                Nov 14 '16 at 5:27













              up vote
              5
              down vote










              up vote
              5
              down vote









              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, you can manually remove the package through dpkg. Running sudo dpkg -P bsnes should purge bsnes.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 24 '14 at 2:56









              saiarcot895

              9,40422233




              9,40422233








              • 2




                dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
                – endolith
                Nov 14 '16 at 5:27














              • 2




                dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
                – endolith
                Nov 14 '16 at 5:27








              2




              2




              dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
              – endolith
              Nov 14 '16 at 5:27




              dpkg: error processing package libcuda1-340 (--purge): package is in a very bad inconsistent state; you should reinstall it before attempting a removal
              – endolith
              Nov 14 '16 at 5:27










              up vote
              2
              down vote













              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)






              share|improve this answer



























                up vote
                2
                down vote













                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)






                share|improve this answer

























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  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)






                  share|improve this answer














                  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)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 19 '16 at 11:00









                  Nick Weinberg

                  3,40841827




                  3,40841827










                  answered Nov 19 '16 at 10:24









                  Vikas Avnish

                  1211




                  1211






















                      up vote
                      0
                      down vote













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


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






                      share|improve this answer

























                        up vote
                        0
                        down vote













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


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






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









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


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






                          share|improve this answer












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


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







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Feb 23 at 17:09









                          Uddhav Gautam

                          1716




                          1716

















                              protected by Community Oct 1 '17 at 19:25



                              Thank you for your interest in this question.
                              Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                              Would you like to answer one of these unanswered questions instead?



                              Popular posts from this blog

                              How did Captain America manage to do this?

                              迪纳利

                              南乌拉尔铁路局