While trying to fix an issue with Python, I accidentally blew away my libz.so.1
binary by symlinking over it. Now a bunch of stuff, including apt-get
won't work. The damage is limited to just libz.so.1 (which was pointing to libz.so.1.2.8
) so I should be able to fix it by just finding the x86_64 binary and dropping it back in place, but all I can find is the source and I can't get that to compile. I'm on Xenial. Where can I find a compiled binary?
3 Answers
The correct way to fix this problem is to download needed package by hand, then install or extract it to the system. Of course you can perform such actions from LiveCD/LiveUSB.
How to solve such problems:
- Visit packages.ubuntu.com.
Enter missed file name in Search the contents of packages (in our case
libz.so.1.2.8
) specifying target Distribution (xenial
in our case) and CPU Architecture (amd64
):Click Search, it will show the results page:
Then click on the
zlib1g
linkIn Download section click
amd64
:On opened page select nearest mirror, (copy link or download deb-file by browser)
wget http://mirrors.kernel.org/ubuntu/pool/main/z/zlib/zlib1g_1.2.8.dfsg-2ubuntu4_amd64.deb
Try to install downloaded package to the system:
sudo dpkg -i zlib1g_1.2.8.dfsg-2ubuntu4_amd64.deb
If it does not work - extract it directly to filesystem:
sudo dpkg -x zlib1g_1.2.8.dfsg-2ubuntu4_amd64.deb /
And then for sure reinstall it with APT:
sudo apt-get install --reinstall zlib1g
-
1This may need to be done from a Live CD, as
dpkg
will probably fail as well.– fkraiemMay 14, 2018 at 9:45 -
1It is hard to broke
dpkg
, I have repaired many systems with brokenapt
with my method.dpkg
was alive, butapt
/apt-get
was broken. Just tested on VM - removed libz withrm
libs, then rebooted -dpkg
works,apt
is broken.– N0rbertMay 14, 2018 at 9:55 -
2Well it is easy to get a list of the libraries
dpkg
needs:ldd /usr/bin/dpkg
. Indeedlibz
is not among them, but there are some.– fkraiemMay 14, 2018 at 13:22 -
-
1Yes,
dpkg
was broken too, on my Ubuntu 18. Like all Internet connections (LAN and WiFi,ip-config-unavailable
in/var/log/syslog
), archiver, and other system tools. So, I download the file according this answer via LiveCD, then unpackdeb
, copiedlibz.so.1
to/usr/local/lib
my hdd, after reboot anddpkg -i ...
andapt-get --reinstall ...
...– bl79Jan 28, 2019 at 9:33
An extension to N0rbert's instructions, if you are doing this in a live session, make sure you are extracting the package to the root of your broken Ubuntu install, as opposed to the root of the live session itself (which won't solve anything and will disappear upon restart).
From the POV of the live session, your broken install will be mounted at something like /media/ubuntu/ae7r0-9s90s-ejf8d-d9d9f
(not actual value, but some long hash similar to that). You may have to browse to it in the file explorer to get the folder to appear.
So in the live session you'd extract using a command such as the following:
sudo dpkg -x zlib1g_1.2.8.dfsg-2ubuntu4_amd64.deb /media/ubuntu/ae7r0-9s90s-ejf8d-d9d9f/
Once the missing libz.so.1
is restored to /media/ubuntu/ae7r0-9s90s-ejf8d-d9d9f/lib/x86_64-linux-gnu/
, you should be able to restart, run sudo apt-get install --reinstall zlib1g
in tty1, and reboot into a working system again.
Ok, since I blew the original file away, I couldn't apt
or even unzip or use rpm
or alien
. I was able to find an RPM'd version but I couldn't get the binary out because none of the tools that rely on compression worked. So I uploaded the RPM to Convertio and converted it to a tar, downloaded it and extracted it and put it back where it belongs.
Sheesh, lesson learned, be careful with those shared libs!
apt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
It's in/lib/x86_64-linux-gnu/libz.so.1.2.8