Ubuntu – How to fix broken libstdc++6, which also breaks apt


I seem to have messed up something with a manual gcc update sometime in the past, which didn't become a problem until today, when I upgraded from 14.04 to 16.04. Namely, the system seems to think that the libstdc++6 version is OK, while apt (and many other programs) complain it isn't (because the shared library is actually in the wrong version):

sudo apt-get install --fix-broken --fix-missing
apt-get: relocation error: /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0: symbol _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

The system doesn't even start a graphical mode, the above output was obtained using a non-graphical console (using Ctrl-Alt-F6), and apt itself is completely unusable, so I can't just do something like a reinstall.

How can I fix and reinstall these packages, when the program I'm using for managing them itself is affected and unusable?

Best Answer

  • At first, I was able to get a graphical login shell by manually copying libstdc++.so.6.0.21 into its place from a Live USB stick, and creating a link to it from libstdc++.so.6. I used this exact version because it seems to be the default for Ubuntu 16.04 and also contains the "21" mentioned in the error message ("version GLIBCXX_3.4.21").

    While this seemed to satisfy the graphics stack, the same errors remained with apt and other programs depending on libstdc++6. After some trying, I could resolve the whole thing with the following steps, using dpkg to manually (un)install things:

    • Download the deb files in the right versions for 16.04:

      wget http://mirrors.kernel.org/ubuntu/pool/main/a/apt/apt_1.2.10ubuntu1_amd64.deb http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb
    • Removing this specific version, which blocked installing the correct libstdc++6:

      sudo dpkg --force-depends -r libstdc++6:i386
    • Then install the "good" version from the files:

      sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.4_amd64.deb apt_1.2.10ubuntu1_amd64.deb
    • And finally, fix the mess I left while updating and trying things out:

      sudo apt-get install -f
  • Related Question