Executing a compiled binary, launching an application, or running a database daemon in Linux only to be halted by the error: ./application: error while loading shared libraries: libexample.so.1: cannot open shared object file: No such file or directory terminates execution immediately. In Linux operating systems, dynamically linked executables do not bundle all supporting code within the binary; instead, they rely on the dynamic linker/loader (ld.so or ld-linux.so) to discover, load, and link shared object libraries (.so files) at runtime. When an essential shared library is missing from the system, installed in a non-standard directory not indexed in /etc/ld.so.conf, or when the dynamic linker cache (/etc/ld.so.cache) has not been refreshed following software compilation, the binary cannot resolve its dependencies and aborts launch. This guide provides step-by-step methods to identify missing libraries and restore binary execution.
Why Does the “cannot open shared object file” Error Occur?
Dynamic linker failures originate from missing packages, search path omissions, and cache desynchronisation:
- Missing Required Library Package: The shared object library is simply not installed on the system (e.g. missing
libssl.so.1.1,libstdc++.so.6, orlibpng16.so.16). - Unindexed Library Installation Directory: Software compiled from source installed libraries into
/usr/local/lib/or a custom directory, but the dynamic linker was not instructed to search that location. - Outdated Dynamic Linker Cache: A newly installed shared library is present on disk, but the operating system has not refreshed its binary lookup table in
/etc/ld.so.cachevialdconfig. - 32-Bit vs 64-Bit Architecture Mismatch: Attempting to run a 32-bit (i386) executable on a 64-bit (x86_64) system without installing multiarch compatibility libraries.
- Broken Library Version Symbolic Links: The base library file exists (e.g.
libfoo.so.1.0.2), but the expected version symlink (libfoo.so.1) is missing.
Method 1: Inspect Missing Dependencies with ldd
The ldd (List Dynamic Dependencies) utility inspects the binary’s ELF header and prints all required shared objects along with their resolved filesystem paths.
- In your terminal, navigate to the directory containing the binary.
- Run
lddagainst the executable:ldd ./your_binary_name - Scan the output for lines marked with:
=> not found - Example output:
libssl.so.1.1 => not found libcrypto.so.1.1 => not found libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9...) - Note the exact filename of every library marked as “not found”.
Method 2: Identify and Install the Missing Package
Use your distribution’s package manager search tools to determine which repository package provides the missing .so file.
- On Ubuntu / Debian:
- Install
apt-fileto search package contents:sudo apt install apt-file && sudo apt-file update - Search for the missing shared library:
apt-file search libexample.so.1 - Install the package reported by apt-file:
sudo apt install libexample1
- Install
- On RHEL / CentOS / Rocky Linux / Fedora:
- Query which RPM package provides the library using DNF:
sudo dnf provides "*/libexample.so.1" - Install the matching package:
sudo dnf install libexample
- Query which RPM package provides the library using DNF:
Method 3: Refresh the Dynamic Linker Cache with ldconfig
If you compiled the library from source or placed it on disk manually, update the dynamic linker index.
- Check if the library exists in common system directories:
find /usr -name "libexample.so*" 2>/dev/null - If the library is found inside
/usr/local/libor/usr/lib, rebuild the linker cache:sudo ldconfig - Verify that the linker now recognizes the library:
ldconfig -p | grep libexample - Relaunch your binary.
Method 4: Add Custom Directories to /etc/ld.so.conf.d/
If your application installed libraries into a dedicated folder (e.g. /opt/myapp/lib), permanently register the path.
- Create a new configuration file in
/etc/ld.so.conf.d/:sudo nano /etc/ld.so.conf.d/myapp.conf - Add the absolute path to your application’s library folder:
/opt/myapp/lib /usr/local/lib - Save and exit (Ctrl + O, then Ctrl + X).
- Update the linker cache:
sudo ldconfig
Method 5: Set the LD_LIBRARY_PATH Environment Variable (Temporary Fix)
If you do not have root administrative privileges, instruct the shell to search local directories using LD_LIBRARY_PATH.
- Export the environment variable for your current terminal session:
export LD_LIBRARY_PATH="/path/to/custom/libs:$LD_LIBRARY_PATH" - Execute your binary:
./your_binary_name - To make this permanent for your specific user account, append the export line to your
~/.bashrcfile:echo 'export LD_LIBRARY_PATH="/path/to/custom/libs:$LD_LIBRARY_PATH"' >> ~/.bashrc source ~/.bashrc
Shared Library Resolution Diagnostic Matrix
| Diagnostic Tool / Output | Meaning | Required Action |
|---|---|---|
ldd binary => "not found" |
Shared library missing from all known linker search paths | Install providing package via apt-file or dnf provides |
| Library exists on disk but binary still fails | Dynamic linker cache not updated after installation | Run sudo ldconfig to refresh /etc/ld.so.cache |
| Library installed in /usr/local/lib or /opt | Directory not listed in standard search paths | Add path to /etc/ld.so.conf.d/*.conf > run sudo ldconfig |
| “wrong ELF class: ELFCLASS32” | 64-bit binary attempting to load 32-bit library (or vice versa) | Install matching architecture version (e.g. libssl:amd64 or libssl:i386) |
Frequently Asked Questions
What is the difference between .so files and .a files in Linux?
A .so (Shared Object) file is a dynamically linked library loaded into memory at runtime, allowing multiple running programs to share a single copy of the code. A .a (Archive) file is a statically linked library whose compiled machine code is embedded directly into the executable binary at compile time.
Why is using LD_LIBRARY_PATH globally in /etc/environment discouraged?
Globally exporting LD_LIBRARY_PATH can override standard system libraries, causing core system binaries (like ls, grep, or sudo) to fail or introduce security vulnerabilities. It is best practice to use /etc/ld.so.conf.d/ or set LD_LIBRARY_PATH only within dedicated application startup scripts.