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?

  • 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… – isomorphismes Jul 28 '17 at 14:30

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
  • 15,657
Sagar Jha
  • 1,073
  • 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... – Zachary Fields Jul 20 '16 at 07:58
  • @Zachary What is the exact issue you're facing? Are you able to boot? – Sagar Jha Jul 20 '16 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. – Zachary Fields Jul 20 '16 at 17:04
  • That is very unlikely. dpkg should be present. See this: http://askubuntu.com/questions/452615/told-command-dpkg-cannot-be-found – Sagar Jha Jul 22 '16 at 15:40
  • I appreciate your statistical analysis, but dpkg is not present in what is booting. However, mv and cp where both available, so I moved the things I wanted to keep into a folder visible from the bootable USB media, copied the files to a thumbdrive and flashed the machine to a fresh install of 16.04. All is well. – Zachary Fields Jul 22 '16 at 17:50
  • Can you please tell how to download it and install using the terminal itself. I am having the same issue of flickering and apt commands. But dpkg is working. – Ankit Agarwal Jul 30 '16 at 16:41
  • To install the .deb file, run the following command on terminal: wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.3.1-14ubuntu2.1_amd64.deb. The link is for 64-bit ubuntu. If you have a 32-bit instead, replace amd64 by i386 in the link. You can also open the link in the browser, if that is possible. – Sagar Jha Jul 30 '16 at 17:23
  • 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 '16 at 04:25
  • thank you, I had stuck at flash screen after upgrade from 14.04 until I read this post. – Jared Chu Oct 22 '16 at 17:35
  • This also solved my problem. My system (Debian laptop) had the drive fail. I was able to ddrescue most of the drive to a new SSD. It would then boot but couldn't start X with a libvirt failure. I tried to reinstall libvirt and got an error similar enough to OP's that i ended up here. Manually installing the .deb for my distro solved the problem (though a couple other programs have had to be reinstalled). – user1794469 Apr 18 '17 at 14:22
  • 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 '17 at 05:49
  • I needed --auto-deconfigure as an extra argument to dpkg -i. – isomorphismes Jul 28 '17 at 15:25
  • That file has apparently disappeared... – jjmerelo Feb 24 '19 at 09:50
  • I'm running on a armhf arch, and the link provided doesn't have a download for it. Any idea what to do? – dotconnor Aug 07 '19 at 05:22
  • I had to install several more packages to solve this issue, see https://askubuntu.com/a/1437932/1179344 – ferdymercury Oct 28 '22 at 18:55
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.

  • 4
    At least for me, this fails with message identical to the one in the question... – mbdevpl Jun 26 '16 at 12:10
  • 1
    Should probably be expanded with answers from below, because obviously ppa-purge won't work (same python) – user64204 Jun 30 '16 at 21:34
  • 1
    I get: sudo: ppa-purge: command not found – Garrett Aug 25 '16 at 03:41
  • @Garrett sudo apt install ppa-purge – Nico Schlömer Aug 25 '16 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 '16 at 23:57
  • After I cleaned this up it recurred every time I installed another package with apt. It looks like some maintenance script in the libc-bin package was blindly updating the libstdc++.so.6 link to point to libstdc++.so.6.0.22. Removing /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 solved this problem. – nmgeek Apr 01 '18 at 21:24
  • I had to use the second solution, download the libstdc++6 .deb separately with wget or curl and then dpkg -i --auto-deconfigure on the .deb file. – BjornW Apr 03 '18 at 15:27
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.

Kalle Richter
  • 6,180
  • 21
  • 70
  • 103
Matjaz
  • 121
  • 1
  • 6
  • 3
    i tried this but got an import error on package apt_pkg – Mixone Aug 21 '16 at 08:17
  • Mixone, what was the exact error and on which command exactly? – Matjaz Aug 23 '16 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 '16 at 07: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 '16 at 04: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 01 '18 at 23:21
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...

  • 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 '16 at 00: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 '17 at 18:20
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
  • 70,465
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
  • 2
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
  • 70,465
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
  • 70,465
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,733
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
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,370
  • 1
  • 21
  • 38
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