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

Solution 1:

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