What the "library-not-found" Error Means
The library-not-found error (often seen as error while loading shared libraries: libxxx.so: cannot open shared object file: No such file or directory) occurs when the Linux dynamic linker (ld.so) cannot locate a required shared library (a file with the .so extension) at runtime.
Typical scenario: You try to run a compiled application or script and receive a message like this instead of execution:
./myapp: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
The system found the myapp executable, but it requires the libssl.so.1.1 library to function, which is not in the paths the linker checks.
Common Causes
- Missing library package. The most frequent cause. The required package (e.g.,
libssl-devoropenssl) is not installed on the system. - Library is installed but in a non-standard path. The dynamic linker, by default, searches for libraries only in
/lib,/usr/lib,/usr/local/lib, and their architecture-specific subdirectories (e.g.,/usr/lib/x86_64-linux-gnu). If the library resides in/opt/libor a home directory, it won't be found. - Architecture mismatch. You are trying to run a 32-bit application, but only the 64-bit version of the library is installed (or vice versa).
- Corrupted or incomplete package installation. Library files may have been deleted or damaged.
- Outdated library version. The application requires a specific version (e.g.,
libssl.so.1.1), while the system has a newer (libssl.so.3) or older version installed. Symbolic links may be misconfigured. - Missing
ldconfigstep. After manually installing a library into a standard path, the linker's cache must be updated.
Solutions
Method 1: Install the Missing Package via Package Manager (Recommended)
This is the most correct and systematic approach, as the package manager handles dependencies, paths, and cache updates automatically.
- Identify the missing package. Use the
lddcommand on the problematic executable. It will list all dependencies and mark those that are not found.ldd /path/to/your/executable
Example output:linux-vdso.so.1 (0x00007ffd5b9f8000) libssl.so.1.1 => not found libcrypto.so.1.1 => not found libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8c1a000000) /lib64/ld-linux-x86-64.so.2 (0x00007f8c1a400000)
Here, packages providinglibssl.so.1.1andlibcrypto.so.1.1are missing. - Find the package containing the library. For Debian/Ubuntu, use
apt-file. Install it first if necessary:sudo apt update && sudo apt install apt-file. Then update the database and search:sudo apt-file update apt-file search libssl.so.1.1
The output will contain lines like:libssl1.1: /usr/lib/x86_64-linux-gnu/libssl.so.1.1 libssl1.1: /usr/lib/x86_64-linux-gnu/libssl.so.1.1.0
The package name islibssl1.1.
For RHEL/CentOS/Fedora, useyum providesordnf provides:yum provides "*/libssl.so.1.1"
For Arch Linux:pacman -Fy libssl.so.1.1 - Install the found package.
- Debian/Ubuntu:
sudo apt install libssl1.1 - RHEL/CentOS 7/8:
sudo yum install openssl-libs - Fedora:
sudo dnf install openssl-libs - Arch Linux:
sudo pacman -S openssl
- Debian/Ubuntu:
- Update the linker cache (usually done automatically on package install, but for completeness):
sudo ldconfig - Run the application again. The error should be resolved.
Method 2: Manual Library Installation from Source
If the required library version is not available in your distribution's repositories, you can install it manually.
- Download the library's source code from the official website or GitHub (e.g., for OpenSSL:
https://www.openssl.org/source/). - Extract the archive and navigate into the directory:
tar -xzf openssl-1.1.1w.tar.gz cd openssl-1.1.1w - Configure, compile, and install. Typically, the
/usr/localprefix is used (a standard path already inldconfig's cache). For a 64-bit system:
The./config --prefix=/usr/local --openssldir=/usr/local/openssl shared make -j$(nproc) sudo make installsharedflag is crucial—it builds shared libraries (.so), not just static ones (.a). - Update the cache:
sudo ldconfig - Verify the library file exists:
ls -l /usr/local/lib/libssl.so.1.1.
Method 3: Add a Non-Standard Path via LD_LIBRARY_PATH
If the library already exists on the system but resides in a non-standard location (e.g., you installed it to ~/mylibs), you can temporarily "tell" the linker where to look.
- Set the
LD_LIBRARY_PATHenvironment variable. Prepend the path to the directory containing the libraries:export LD_LIBRARY_PATH=/home/your_user/mylibs:$LD_LIBRARY_PATH- Important: The path must point to the directory containing the
.sofiles, not to the file itself. - This setting only affects the current shell session. For a permanent effect, add the line to
~/.bashrc,~/.zshrc, or~/.profile.
- Important: The path must point to the directory containing the
- Launch the application from the same terminal session. It will now be able to find the libraries.
- For debugging, you can see which paths are checked using
ldd(it will now account forLD_LIBRARY_PATH) orLD_DEBUG=libs ./your_application.
Method 4: Create Symbolic Links (symlinks)
If you have the correct version of the library but it has a different name (e.g., libssl.so.1.1.0 instead of libssl.so.1.1), create a symlink.
- Find the actual library file:
sudo find /usr -name "libssl.so*" 2>/dev/null
Example output:/usr/lib/x86_64-linux-gnu/libssl.so.1.1.0. - Create a symlink in a directory already in the cache (e.g.,
/usr/lib/x86_64-linux-gnu/):cd /usr/lib/x86_64-linux-gnu sudo ln -s libssl.so.1.1.0 libssl.so.1.1 sudo ln -s libcrypto.so.1.1.0 libcrypto.so.1.1 # if needed for that too - Update the cache:
sudo ldconfig
Method 5: Rebuild the Application with Correct Paths
If you are compiling an application from source yourself, ensure the linker knows where to find libraries during the build.
- Install the
-dev/-develpackages. These contain header files (.h) and symlinks for compilation (e.g.,libssl-devfor OpenSSL).sudo apt install libssl-dev # Debian/Ubuntu sudo yum install openssl-devel # RHEL/CentOS - Use compiler flags during the build. Typically,
pkg-configautomatically inserts the correct paths:gcc myapp.c -o myapp $(pkg-config --cflags --libs openssl)
Or specify them explicitly:gcc myapp.c -o myapp -I/usr/include/openssl -L/usr/lib/x86_64-linux-gnu -lssl -lcrypto-I— path to headers.-L— path to libraries (during linking).-l— library name without thelibprefix and.soextension.
- The built application will then look for libraries in standard system paths, making a
library-not-founderror unlikely.
Prevention
- Use package managers (
apt,yum,pacman) to install libraries. They guarantee proper placement and dependency tracking. - Check dependencies before building. For C/C++ programs, use
pkg-config --exists <library>or check for header files (#include <lib.h>). - Document custom paths. If you install libraries in non-standard locations (e.g.,
/opt/), be sure to document this and configureLD_LIBRARY_PATHor add configuration files to/etc/ld.so.conf.d/(after whichsudo ldconfigis required). - Update your system regularly:
sudo apt update && sudo apt upgrade. This helps avoid version conflicts. - Before running a third-party binary file, check its dependencies with
lddand ensure all libraries are found (=> /path/to/fileinstead of=> not found).
💡 Tip: To permanently add a non-standard path (e.g.,
/usr/local/lib) told.so's search path, create a configuration file:echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/usr-local.conf sudo ldconfigThis is a cleaner solution than using
LD_LIBRARY_PATHglobally.