apt: relocation error: version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

Since trying to upgrade to 16.04 xenial, I'm getting

$ apt
apt: 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

when simply running apt. Needless to say this makes it difficult to do anything.

Any hints?


Solution 1:

I had the same problem caused by issues from PPA for Ubuntu toolchain. My computer would not boot because of it. Following @w00kie's comment on his answer, I downloaded (from tty terminal) the debian of package libstdc++6 for Xenial at link https://packages.ubuntu.com/xenial/libstdc++6 and installed using dpkg -i. The computer works just fine now.

Steps

wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb

# I also found this helpful
sudo apt-get -f install

Solution 2:

The culprit are left-overs from the PPA for Ubuntu Toolchain Uploads (restricted), specifically

/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22

There are two possibilities of dealing with this:

  • You already have ppa-purge installed. Then

    sudo ppa-purge ppa:ubuntu-toolchain-r/test
    

    fixes the issues.

  • Override the libstc++ by downloading libstdc++6 for Xenial and installing it via dpkg -i.

Solution 3:

My comp failed to boot correctly because of this error. Apt-get was not working, nor was Gnome. This was immediatelly after an upgrade from 14.04 to 16.04. I solved it in tty by entering

sudo apt-add-repository --remove ppa:ubuntu-toolchain-r/test

At this point apt-get started to work again and I was able to fix all isues from there:

sudo apt-get clean
sudo apt-get update
sudo apt-get install -f
sudo dpkg -a --configure
sudo apt-get dist-upgrade

I also had to uninstall Virtualbox (after the update command) and reinstal it later, but I think this was unrelated.