68

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?

13 Answers13

58

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
Pablo Bianchi
  • 17,371
Sagar Jha
  • 1,083
27

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.

8

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.

Matjaz
  • 121
  • 1
  • 6
4

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...

4

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

gcc-5-base_5.4.0-6ubuntu1~16.04.4_i386.deb
libstdc++6_5.4.0-6ubuntu1~16.04.4_i386.deb

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

Zanna
  • 72,312
2

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:

https://bugs.launchpad.net/snappy/+bug/1a677417

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).

Ivy
  • 21
1

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
Zanna
  • 72,312
1
  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  
    
Zanna
  • 72,312
0

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.

Ruslan
  • 1,863
0

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.

0

You should be able to fix it by typing:

sudo apt-get -f install

without specifing any package. It should do the work.

biljkus
  • 27
  • 6
0

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.

AnotherKiwiGuy
  • 4,482
  • 1
  • 22
  • 39
0

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.6.0.20*
libstdc++.so.6.0.21
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

Resulting:

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

and everything came back to normal