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?

  • wow … this makes me really distrust Ubuntu/Canonical’s upgrade process. Every time I have a working but stale version, someone in a help forum tells me upgrades will solve all my problems…I don’t know what a "scratch disk" is, and certainly don’t want to have to interrupt work with GRUB debugging… Jul 28, 2017 at 14:30

13 Answers 13


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.


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
  • 5
    Can you please put the commands, step by step in your answer? I'm not familiar with this at all and my linux machine is horked... Jul 20, 2016 at 7:58
  • @Zachary What is the exact issue you're facing? Are you able to boot?
    – Sagar Jha
    Jul 20, 2016 at 13:14
  • 1
    Not really. If I let it go the screen flickers for about 15 mins, then I get a tty2 terminal prompt in a very light grey color. I'm unable to use apt (or any tool really). I have even tried to download libstdc++6...deb from a bootable USB drive, manually place the package, reboot into the broken system and installing the .deb using sudo dpkg -i libstdc++6...deb, but it doesn't even know what dpkg is. Jul 20, 2016 at 17:04
  • 13
    To download/install the .deb file, you can do: wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.2_amd64.deb and then once that downloads, dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.2_amd64.deb (assumes 64-bit system). For me, my internet connection wasn't working, so I downloaded it onto a USB drive from a different computer, then had to manually mount the USB drive on my problematic computer (sudo mount /dev/sdc1 /media/usb where sdc1 was found by watching terminal output right after plugging in USB ) and then run the above dpkg command.
    – Garrett
    Aug 25, 2016 at 4:25
  • 8
    I had to use dpkg --force-all -i libstdc+‌​+6_5.4.0-6ubuntu1~16‌​.04.2_amd64.deb to get it installed
    – virtualxtc
    Jul 26, 2017 at 5:49

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


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.

  • 4
    At least for me, this fails with message identical to the one in the question...
    – mbdevpl
    Jun 26, 2016 at 12:10
  • 1
    Should probably be expanded with answers from below, because obviously ppa-purge won't work (same python)
    – user64204
    Jun 30, 2016 at 21:34
  • 1
    I get: sudo: ppa-purge: command not found
    – Garrett
    Aug 25, 2016 at 3:41
  • @Garrett sudo apt install ppa-purge Aug 25, 2016 at 15:04
  • 3
    @NicoSchlömer, thanks, but actually, I believe my apt was also not working (as per the original post).
    – Garrett
    Aug 25, 2016 at 23:57

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.

  • 3
    i tried this but got an import error on package apt_pkg
    – Mixone
    Aug 21, 2016 at 8:17
  • Mixone, what was the exact error and on which command exactly?
    – Matjaz
    Aug 23, 2016 at 10:22
  • sudo apt-get update the error came from the python backend i guess, the stacktrace was python and it basically said cannot find module apt_pkg
    – Mixone
    Aug 24, 2016 at 7:49
  • 5
    Same problem for me too, trying to use the apt-add-repository command in your answer gives: ImportError: /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0: symbol _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_, version GLIBCXX_3.4.21 not defined in the file libstdc++.so.6 with link time reference
    – Garrett
    Aug 25, 2016 at 4:10
  • For idiots like me trying to upgrade 2 years after the release and thinking all the bugs are fixed. Link in the comment above is broken. Here is the new one. http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb (or i386 or both) And don't mind dpkg cursing you. Do --auto--deconfigure and your apt-get will be back on track afterwards despite error messages. And you will be able to finish with proper -f --install + --upgrade and reboot into a fresh system.
    – Ufos
    Jul 1, 2018 at 23:21

I had been thinking the problem was something unique to me, and was caused by a download error.

This discussion gave me the clue I needed. Basically, all that was needed was to replace libstdc++.so.6.0.22 with libstdc++.so.6.0.21 in /usr/lib/x86_64-linux-gnu of the failing system. (It seems there's an error in the newer version.)

This can be done from a thumb-drive or, as in my case, from a scratch disk.

Full details at: https://answers.launchpad.net/ubuntu/+question/395832

Thanks to all...

  • I used this trick, but did a dual boot on some spare space. I was able to easily mount the original partition. It was pretty easy.
    – Andrew
    Sep 22, 2016 at 0:53
  • Awesome - these 3 commands worked for me: cd /usr/lib/x86_64-linux-gnu/ >>> sudo rm libstdc++.so.6 >>> sudo ln -s libstdc++.so.6.0.21 libstdc++.so.6
    – osman
    May 17, 2017 at 18:20

Following the dpkg -i approach in the accepted answer, my 14.04->16.04 upgrade required not one but two packages:


After this, apt upgrade was able to download the remaining packages and complete the installation.


If you have the latest version of the 'conjure-up' snap installed with Snappy on Yakkety, your apt will be broken with a very similar error:

apt: relocation error: /usr/lib/x86_64-linux-gnu/libapt-private.so.0.0: symbol _ZN13pkgSourceList16AddVolatileFilesER11CommandLinePSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS8_EE, version APTPKG_5.0 not defined in file libapt-pkg.so.5.0 with link time reference

due to this bug:


Currently the only workaround I know of is the remove the conjure-up snap (or possibly 'snap revert' it to a previous version if you had one installed prior).


The fix that worked for me was to actually add the Ubuntu toolchain ppa back:

sudo apt-add-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -f
sudo apt-get upgrade
  1. Download libstdc++6 for your ubuntu from Ubuntu package manager website. ( use uname -a to find the h/w and s/w architecture).

  2. Run

    sudo dpkg --install --auto-deconfigure libstdc++6...deb
  3. Reboot. Ubuntu should boot but apt would not install new packages.

  4. To fix dependencies and make system up to date, run these commands

    sudo apt-add-repository ppa:ubuntu-toolchain-r/test
    sudo apt-get update
    sudo apt-get install -f
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    sudo apt-get autoclean && sudo apt-get autoremove  

You should be able to fix it by typing:

sudo apt-get -f install

without specifing any package. It should do the work.


There can be a very similar problem with i386 systems.

To solve the problem, I also had to downgrade gcc-5-base from Version 5.4.1-2ubuntu1~12.04 to 5.4.0-6ubuntu1~16.04.4.

To complete the upgrade to a reasonable-seeming system, I also had to use dpkg --purge on vituoso_nepomuk and virtualbox to get rid of their configuration files, which were causing trouble (for me, VirtualBox is provided by package virtualbox-5.1, which seems unscathed by the upgrade.)

The key was to get dpkg --configure dbus to work.

To enable wget while in a tty-type screen, users may also need to execute sudo dhclient eth0 to enable a wired ethernet connection.


I've just had this problem when upgrading ubuntu distribution on linux I saw that:

# ls /usr/lib/x86_64-linux-gnu/libstdc++.so.6*
libstdc++.so.6 -> libstdc++.so.6cd*
libstdc++.so.6cd -> libstdc++.so.6.0.20*

libstdc++.so.6 -> libstdc++.so.6cd -> libstdc++.so.6.0.20

But there were two files: libstdc++.so.6.0.21 and libstdc++.so.6.0.20

I've changed the symbolic link to point to latest version libstdc++.so.6.0.21

cd /usr/lib/x86_64-linux-gnu
rm libstdc++.so.6cd
chmod +x libstdc++.so.6.0.21
ln -s  libstdc++.so.6.0.21 libstdc++.so.6cd


libstdc++.so.6 -> libstdc++.so.6cd*
libstdc++.so.6cd -> libstdc++.so.6.0.21*

and everything came back to normal


After installing libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb as mentioned in the answer by Sagar Jha (this newer version is currently relevant) via dpkg --force-all -i THE_FILENAME.deb, I had package dependencies broken in a way that apt-get -f install was unable to fix. But apt itself is now working. So to get my system back to a working state, I had to explicitly install the specific versions of all the broken packages from the toolchain-r ppa, like here:

sudo apt install {gcc-5-base,cpp-5,g++-5,gcc-5,libasan2,libgcc-5-dev,libstdc++-5-dev,libmpx0}=5.4.0-6ubuntu1~16.04.12

This then let apt downgrade and finally lead package system to a consistent state.


the only thing you have to do is copying /usr/lib/x86_64-linux-gnu/libstdc++.so.6 from the normal 16.04 ubuntu. This is the most simplest way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .