Home › Linux & shell

error while loading shared libraries: cannot open shared object file: No such file or directory (Linux) — how to fix

./myapp: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

Quick fix: Find the missing libs with ldd ./myapp | grep 'not found', install the package that provides them (apt-file search libfoo.so.1 / dnf provides '*/libfoo.so.1'), and if the library is in a custom directory, add it to /etc/ld.so.conf.d/ and run sudo ldconfig (or set LD_LIBRARY_PATH for a quick test).

What it means

Dynamically linked programs list the shared libraries they need (NEEDED entries). At start-up the dynamic linker (ld-linux.so) looks for each one in the paths from LD_LIBRARY_PATH, the binary's RPATH/RUNPATH, the cache built by ldconfig from /etc/ld.so.conf, and the default directories (/lib, /usr/lib and their multiarch variants). If one is not found, the program doesn't start at all.

See every library and which are missing:

ldd ./myapp | grep "not found"

Do not run ldd on untrusted binaries; use objdump -p ./myapp | grep NEEDED instead.

Cause 1: the library package isn't installed

Find which package ships the file and install it.

Debian/Ubuntu:

sudo apt install apt-file && sudo apt-file update
apt-file search libpq.so.5
sudo apt install libpq5

Fedora/RHEL:

dnf provides '*/libpq.so.5'
sudo dnf install libpq

Runtime library packages are usually named like libfoo1/libfoo and don't need the -dev/-devel package.

Libraries you built yourself usually go to /usr/local/lib, and vendor software often uses /opt/<vendor>/lib. If the file exists but isn't found:

sudo find / -name 'libfoo.so*' 2>/dev/null

Register the directory and rebuild the linker cache:

echo "/opt/vendor/lib" | sudo tee /etc/ld.so.conf.d/vendor.conf
sudo ldconfig
ldconfig -p | grep libfoo     # verify

After make install into /usr/local/lib, running sudo ldconfig is often all that's missing.

For a one-off test, or when you can't use sudo:

LD_LIBRARY_PATH=/opt/vendor/lib ./myapp

Cause 3: wrong version (e.g. libssl.so.1.1 on a newer distro)

The number after .so is the ABI version, and only that exact version satisfies the binary. Newer distributions ship OpenSSL 3 (libssl.so.3), so old binaries asking for libssl.so.1.1 fail. Options, best first:

  1. Install a build of the program made for your distro version.
  2. Install the compatibility package if your distro provides one (search with apt-file search libssl.so.1.1 or dnf provides).
  3. Run the old program in a container based on the distro it was built for.

Don't symlink libssl.so.3 to libssl.so.1.1: different ABI versions are not compatible, and the program may crash or behave insecurely.

Cause 4: 32-bit program on a 64-bit system

file ./myapp shows ELF 32-bit. It needs 32-bit libraries, which live in separate packages. On Debian/Ubuntu:

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 libstdc++6:i386

then the specific libfoo:i386 packages ldd reports.

Cause 5: inside a minimal Docker image

Copying a binary into alpine or a slim/distroless image often leaves out its libraries. Alpine uses musl instead of glibc, so glibc-linked binaries fail there. Install the libraries in the image (apt-get install -y libfoo1), use the same base image as the build stage, or build a statically linked binary.

Last updated 2026-12-02.