2

I ran a command:

sudo apt-get remove libstdc++6

I know, I shouldn't have! .. but now nothing works, not even apt-get, it's not there anymore.

How do I reverse this?

  • 2
    @Aurimas My fix is the only fix, as you've broken your system compiler toolchain. libstdc is REQUIRED for glibc, and glibc is required for everything. Please use the libstdc required by 16.04.2 LTS in the case that you were blindly following directions used for 17.04. The procedure is the same, but the version is different. If you cannot mount a USB on your end and copy the required files over SSH, then a server restore on your host's end is the only option – eyoung100 Oct 23 '17 at 17:21
  • 2
    @eyoung100 no it’s not... – Stephen Kitt Oct 23 '17 at 17:36
  • 1
    @eyoung100 no, wget, sudo and dpkg don’t need libstdc++6 so there is no circular dependency issue here. The OP only needs libstdc++6 to restore apt. You no doubt understand how the toolchain works intricately, but the way the toolchain is packaged in Debian and derivatives means that the dependency chains are more forgiving than the source-based dependency chains. – Stephen Kitt Oct 23 '17 at 17:47
  • 1
    @eyoung100 what you’re not getting (I think) is that on Debian, it’s perfectly OK to have bits of the toolchain installed, you don’t need the whole thing all the time. What’s more, dpkg doesn’t depend on anything from GCC (after it’s built): libbz2-1.0, libc6, liblzma5, libselinux1, zlib1g and tar. The only part of the toolchain that’s required is libgcc1, indirectly. libstdc++6 isn’t needed for dpkg to work. – Stephen Kitt Oct 23 '17 at 18:00
  • 1
    @eyoung100 I work on the toolchain packaging in Debian. We’re not removing support at compile time, we’re packaging parts of the compiler and toolchain separately. Remember, Debian is binary-based, not source-based like Gentoo, so you only need the runtime dependencies to install packages, not the build-time dependencies. The proof of the pudding here is that removing libstdc++6 didn’t nuke the whole system — if it was needed for everything, apt would have removed everything when removing libstdc++6. – Stephen Kitt Oct 23 '17 at 18:19
5

There is no easy rollback feature, but you can reinstall the packages required to get apt up and running again, and proceed from there:

wget http://launchpadlibrarian.net/336920453/libstdc++6_5.4.0-6ubuntu1~16.04.5_amd64.deb
sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.5_amd64.deb

will restore libstdc++6 (for Ubuntu 16.04, assuming you’re running amd64), then

wget http://launchpadlibrarian.net/339152322/apt_1.2.25_amd64.deb http://launchpadlibrarian.net/339152325/libapt-pkg5.0_1.2.25_amd64.deb
sudo dpkg -i apt_1.2.25_amd64.deb libapt-pkg5.0_1.2.25_amd64.deb

will restore apt.

At this point you can look at the logs in /var/log/apt to see what the removal of libstdc++6 took with it, and reinstall those packages using apt.

|improve this answer|||||
  • Thanks, apt seems to work. So if I just copy paste the "The following packages will be REMOVED:" section from the remove command I used to apt-get install I should get everything back? – Aurimas Oct 23 '17 at 18:38
  • Yes, if you still have the list of packages, specifying them as arguments to apt-get install (or apt install) will get everything back. – Stephen Kitt Oct 23 '17 at 18:40
  • Trying that I get one dependency problem: apt-utils : Depends: apt (= 1.2.24) but 1.2.25 is to be installed. Any ideas? – Aurimas Oct 23 '17 at 18:48
  • I downgraded the apt and installed everything, but many things don't work the way they used to.. for examplce, can't start apache2 server for some errors etc. .. I guess in the end it is irreversible. – Aurimas Oct 23 '17 at 19:20
  • Hmm, that’s unfortunate, and somewhat odd... It should be reversible, albeit perhaps complicated to reverse fully; but the whole point of having a package manager is that you can install, remove, and reinstall packages. Especially since you only ran remove, not purge, so the configuration files wouldn’t have been removed. Does apt install -f find anything to fix? Does apt update && apt upgrade upgrade anything? – Stephen Kitt Oct 23 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.