误删libstdc++.so.6后无法通过APT重装该库的解决方法咨询
Hey there, I feel your pain—you followed a tutorial to fix one issue, only to break something way more critical that locks you out of your usual package manager. Let’s work through some practical ways to get libstdc++.so.6 back up and running without relying on a broken apt-get.
方法一:手动下载并解压deb包恢复文件
Since apt-get is dead in the water right now, we’ll bypass it and grab the files directly:
- First, confirm your OS version and architecture (you can check
/etc/os-releasewithcat /etc/os-release—this command should still work even without libstdc++). - Grab the correct
libstdc++6.deb package for your system. Use another internet-connected machine to download it from your distro’s official package repository (make sure to pick the exact version matching your OS). Transfer the .deb file to your broken machine via USB, SSH (if that’s still working), or any other method. - Once you have the .deb file, extract its contents:
- Run
ar x libstdc++6_*.deb—this will create three files:data.tar.xz,control.tar.xz, anddebian-binary. - Extract the actual system files with
tar xf data.tar.xz. This will generate a directory structure matching your system. - Navigate to the extracted lib directory and copy the files to your system’s library folder:
Thecp ./usr/lib/x86_64-linux-gnu/libstdc++.so.6* /lib/x86_64-linux-gnu/*ensures you copy both the soft link (libstdc++.so.6) and the actual underlying library file (likelibstdc++.so.6.0.30).
- Run
- Run
ldconfigto update the system’s dynamic library cache, then test ifapt-getworks again. Once it’s back, runapt-get install --reinstall libstdc++6to make sure all files are properly set up.
方法二:从同版本正常系统拷贝文件
If you have another machine running the exact same OS version and architecture:
- On the working machine, copy the entire set of libstdc++ files from
/lib/x86_64-linux-gnu/—look forlibstdc++.so.6and its corresponding versioned file (e.g.,libstdc++.so.6.0.28). - Transfer these files to your broken machine’s
/lib/x86_64-linux-gnu/directory. - Fix the file permissions if needed:
chown root:root /lib/x86_64-linux-gnu/libstdc++.so.6* chmod 644 /lib/x86_64-linux-gnu/libstdc++.so.6* - Run
ldconfigto refresh the cache, then tryapt-getagain.
方法三:使用静态链接的包管理工具
Some distros offer statically linked versions of package managers that don’t depend on system dynamic libraries:
- Check if your system has
apt-staticinstalled (runapt-static --versionto test). If it does, simply run:apt-static install --reinstall libstdc++6 - If
apt-staticisn’t available, you might look for a statically compileddpkgbinary (though this is less common).
A quick heads-up: Make sure you’re running all these commands as root (use sudo if you can, or switch to root with su).
备注:内容来源于stack exchange,提问作者silverhash

