What Does the "cannot open shared object file" Error Mean?
The error with the text error while loading shared libraries: <library_name>.so: cannot open shared object file: No such file or directory (or its variants, such as ld-linux.so not found) is a critical message from the Linux dynamic loader (ld-linux.so or ld.so).
It means the system failed to find the required shared library (a file with the .so extension) during an attempt to run an executable file (a program, utility, or other binary). The dynamic loader is responsible for resolving a program's dependencies on external libraries. If the required file is not found in the specified paths, the launch is aborted.
Full text of a typical error:
./myapp: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
Here, libssl.so.1.1 is the missing library.
Causes
- The library is not installed. The most common cause. The program requires a specific version of a library (e.g.,
libssl.so.1.1), which is absent from the system. - The library is installed but in a non-standard path. The loader searches for libraries only in paths specified in
/etc/ld.so.confand files in/etc/ld.so.conf.d/, as well as standard locations (/lib,/usr/lib). If the library is located, for example, in/opt/custom/lib, it will not be found. - The loader cache (
/etc/ld.so.cache) is outdated. Even if the library is in the correct place, the loader uses a compiled cache. After installing a new library, the cache must be updated with theldconfigcommand. - Package conflict or corruption. The library may have been removed or corrupted during the update/removal of another package.
- Architecture or glibc version incompatibility. Attempting to run a 32-bit program on a purely 64-bit system without installing 32-bit libraries (
:i386packages in Debian/Ubuntu). Or, a program compiled for a very old/new version of a library that doesn't exist in the current distribution release. - Broken symbolic links. In the library directories, there may be broken links like
libssl.so -> libssl.so.1.1pointing to a non-existent file.
Solutions
Solution 1: Update the loader cache (simplest and most common)
This is the first and mandatory step after installing any new library.
- Open a terminal.
- Execute the command with superuser privileges:
sudo ldconfig - Try running the program again.
What ldconfig does: It scans all directories listed in configuration files /etc/ld.so.conf and /etc/ld.so.conf.d/*.conf, finds libraries there (lib*.so* files), updates (or creates) the cache /etc/ld.so.cache, and updates symbolic links. After this, the loader knows where to find all installed libraries.
💡 Tip: If you just installed a package via a package manager (
apt,dnf), it usually callsldconfigitself. But if you manually copied a.sofile to/usr/local/lib— you must runldconfig.
Solution 2: Install the missing package
If the library does not physically exist on the system, it needs to be installed.
For Debian/Ubuntu and derivatives:
- Find the package name that provides the needed library. The most accurate way:
apt-file search libssl.so.1.1 | head -n 5
Ifapt-fileis not installed, first runsudo apt update && sudo apt install apt-file && sudo apt-file update. - Install the package (example for
libssl.so.1.1):sudo apt update sudo apt install libssl1.1
Or, if a newer version is required:sudo apt install libssl3 - Update the cache:
sudo ldconfig.
For CentOS/RHEL/Fedora/Rocky/AlmaLinux:
- Find the package:
yum provides "*/libssl.so.1.1" # or for dnf dnf provides "*/libssl.so.1.1" - Install the found package (e.g.,
openssl-libs):sudo dnf install openssl-libs - Update the cache:
sudo ldconfig.
Solution 3: Add a non-standard path to ld.so configuration
If the library is in a custom folder (e.g., you compiled and installed a program in /opt/myapp/lib).
- Create a new configuration file (recommended) or edit an existing one:
sudo nano /etc/ld.so.conf.d/custom-apps.conf
Add one line with the full path to the folder containing the.sofiles:/opt/myapp/lib
You can add multiple paths, each on a new line. - Apply the changes:
sudo ldconfig - Verify the path was added to the cache:
ldconfig -p | grep myapp
⚠️ Important: Do not add paths to temporary or untrusted directories in
/etc/ld.so.conf. This is a security matter.
Solution 4: Use the LD_LIBRARY_PATH environment variable (temporary workaround)
This method has the highest priority for the loader but is considered temporary and less secure, as it can lead to loading the wrong libraries.
- Set the environment variable before running the command:
LD_LIBRARY_PATH="/path/to/library_folder:$LD_LIBRARY_PATH" ./your_program
Example:LD_LIBRARY_PATH="/home/user/app/lib:$LD_LIBRARY_PATH" ./myapp - For permanent use (only for the current user), add a line to
~/.bashrcor~/.profile:export LD_LIBRARY_PATH="/home/user/app/lib:$LD_LIBRARY_PATH"
After that, runsource ~/.bashrcor log out and back in.
⚠️ Warning: Avoid global (system-wide) use of
LD_LIBRARY_PATHin/etc/profile. It can break system utilities. Use it only for specific applications or in user scripts.
Solution 5: Reinstall or configure RPATH for a specific binary (advanced)
If you are developing or managing a specific application, you can embed the library search path directly into the binary using the patchelf utility.
- Install
patchelf:# Debian/Ubuntu sudo apt install patchelf # CentOS/RHEL/Fedora sudo dnf install patchelf - Check the current
RPATH(embedded library search path) of the binary:patchelf --print-rpath ./your_program - Set the desired
RPATH(e.g.,$ORIGIN/libto search in alibfolder next to the binary):patchelf --set-rpath '$ORIGIN/lib' ./your_program - Now the binary will look for libraries in the specified relative path, regardless of system settings.
Prevention
- Install packages only from your distribution's official repositories. This guarantees library compatibility.
- Do not remove system libraries manually. Always use the package manager (
apt remove,dnf remove). - After manually installing software (from source, to
/usr/local) always runsudo ldconfigif the installer did not do it. - Use isolated environments (e.g.,
conda,virtualenvfor Python,dockercontainers,flatpak,snap) for applications with non-standard dependencies. This prevents them from conflicting with system libraries. - When compiling from source, use flags like
./configure --prefix=/usr/local(or another clean path) and thenmake install. Standard paths (/usr/local/lib) are already accounted for inld.so.conf.d. - Update your system periodically (
sudo apt update && sudo apt upgrade,sudo dnf upgrade) to receive current and compatible library versions.