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?

GAD3R
  • 66,769
Aurimas
  • 121
  • Which distribution and version are you using? – Stephen Kitt Oct 23 '17 at 17:03
  • 16.04.2 LTS, it's a server, I only have SSH to it. Thanks! – Aurimas Oct 23 '17 at 17:04
  • @eyoung100, it doesn't work for my case, run into some depnedency issues. – Aurimas Oct 23 '17 at 17:07
  • @Aurimas Can new SSH connections be established? (Please don't end your current SSH session--especially not before checking--in case they cannot.) Also, can you [edit] this question to add the details of exact what commands, from there or elsewhere, you have run since to try to fix the problem, and the exact output? You should be able to copy this from the terminal you are using for the SSH session. – Eliah Kagan Oct 23 '17 at 17:09
  • 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
  • @eyoung100 Are you really saying that it's impossible to run any program once libstdc++6 has been removed? The solution you are recommending involves running wget, sudo, and dpkg, all before the library has been reinstalled. Since that procedure has worked for some people, what you seem to be saying cannot possibly be true. Since those programs can run, presumably other programs can too, so long as they don't use the C++ standard library and don't use any libraries or other programs that use it. So presumably other solutions are possible, too. – Eliah Kagan Oct 23 '17 at 17:36
  • I'm not going to argue as I came from Gentoo, where everything was compiled to begin with, I understand how the toolchain works intricately. While I might be a bit rusty in regards to glibc vs binutils re stephenkitt I do know that the OP created a circular dependency issue. wget, sudo, and dpkg were all run from the Live CD/USB. The inherit fact that he broke apt proves my point, as every package on a system was built at some point using a toolchain. Breaking that chain breaks every package, and yes it is impossible to run any program. – eyoung100 Oct 23 '17 at 17:45
  • 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
  • @StephenKitt apt depends on dpkg If your telling me dpkg has no dependencies that depend on something that doesn't require something from the toolchain, I'd like to see that. And maybe gentoo was more strict. – eyoung100 Oct 23 '17 at 17:55
  • 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
  • See also Debtree. I love StackExchange as even this question taught me something.@StephenKitt. See Packages to rebuild after upgrading gcc on gentoo systems. I respectfully disagree about bits of the toolchain being loaded in Debian, as there is no indirectly. Choosing to remove support at compile time is different than loading bits of the toolchain. The support was removed so cases like this could be repaired. – eyoung100 Oct 23 '17 at 18:11
  • 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
  • @eyoung100 and by indirectly, I meant that dpkg doesn’t have a direct dependency on libgcc1, it has an indirect dependency on it via libc6. – Stephen Kitt Oct 23 '17 at 18:21
  • @eyoung100 I have (or had) some things on the server running / installed so I wouldn't want to reset the server as those things will be gone. I would highly prefer to fix this instead. – Aurimas Oct 23 '17 at 18:41
  • @EliahKagan thanks, I figured I shouldn't end the session. I didn't run much, except now what the answer of Stephen suggests, which brought back apt – Aurimas Oct 23 '17 at 18:42

1 Answers1

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.

Stephen Kitt
  • 434,908
  • 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
  • Some errors related to webmin. Apache2 fails with error: SuexecUserGroup configured, but suEXEC is disabled: Missing suexec binary /usr/lib/apache2/suexec Webmin fails with: /etc/init.d/webmin: 13: /etc/init.d/webmin: /etc/webmin/start: not found

    The errors from apt install -f are related to Webmin: Webmin does not appear to be installed on your system. This package cannot be installed unless the Debian version of Webmin is installed first. However, running apt install webmin gives webmin is already the newest version (1.860)

    – Aurimas Oct 23 '17 at 20:54