If you’ve encountered the error message:
error while loading shared libraries: cannot open shared object file: No such file or directory
Don’t worry, you’re not alone! This error occurs when a program can’t find a necessary shared library (also known as a .so
file). Shared libraries are essential components that programs rely on to function correctly. When they’re missing or not properly configured, the program can’t run.
Table of Contents
This guide will walk you through simple steps to resolve the issue.
Step 1: Identify the Missing Library
When you encounter this error, the message usually specifies which shared library is missing. Here’s an example:
error while loading shared libraries: libssl.so.1.1: cannot open shared object file...
In this case, the missing library is libssl.so.1.1
.
Make sure to note the name of the missing library, as it will be important for the next steps.
Step 2: Check if the Library is Installed
Before proceeding with the installation, you should first check if the missing library is already installed on your system. Here’s how you can do it:
- Search for the library on your system:
- You can use the
find
command to search your entire system:sudo find / -name "libssl.so*" 2>/dev/null
Or uselocate
if it’s installed:locate libssl.so
- If the library is found, make note of its location (for example,
/usr/local/lib
). You can skip to Step 4 if it’s found.
- You can use the
- If the library is not found, move on to the next step to install it.
Step 3: Install the Missing Library
If the library is missing, you will need to install it. The installation process varies depending on your distribution.
On Debian/Ubuntu-based systems:
If you are using a Debian or Ubuntu-based system, you can use the apt
package manager to install the library:
sudo apt install libssl-dev
Make sure to replace libssl-dev
with the correct package name if it’s different for your missing library. You can search for the exact package with:
apt search libssl
On Red Hat/CentOS-based systems:
If you’re on a Red Hat or CentOS-based system, use yum
or dnf
:
sudo yum install libssl
or
sudo dnf install libssl
You can search for the library using:
dnf search libssl
Step 4: Update Library Paths
If the library is installed but stored in a non-standard location, the program may not be able to find it. In this case, you can update your library paths.
Temporary Fix (for the current terminal session):
You can temporarily set the library path by running:
export LD_LIBRARY_PATH=/path/to/library:$LD_LIBRARY_PATH
Replace /path/to/library
with the directory where the library is located.
Permanent Fix:
To make the change permanent for all future sessions, follow these steps:
- For system-wide settings: Add the library path to the system configuration:
sudo sh -c 'echo "/path/to/library" >> /etc/ld.so.conf.d/custom.conf' sudo ldconfig
- For user-specific installations: If you only need the fix for a specific user, add the library path to the user’s
~/.bashrc
file:echo 'export LD_LIBRARY_PATH=/path/to/library:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc
Step 5: Rebuild the Linker Cache
After installing the missing library or updating the library paths, it’s essential to rebuild the linker cache to ensure your system is aware of the new or updated libraries.
Run the following command:
sudo ldconfig
This will reload the library paths and ensure the program can find the required libraries.
Step 6: Check for Architecture Compatibility
If the missing library is architecture-specific, such as being built for 32-bit on a 64-bit system, it might not be compatible. Here’s how you can address this:
- Check the system architecture: Use the following command to verify whether your system is 64-bit or 32-bit:
uname -m
- If your system is 64-bit, but the library is 32-bit, you will need to install the 32-bit version of the library.
- Install the 32-bit version (on 64-bit systems): On Debian/Ubuntu-based systems, use:
sudo apt install libxyz:i386
Replacelibxyz:i386
with the appropriate library name.
Step 7: Verify Program Dependencies
To make sure your program isn’t missing other shared libraries, you can use the ldd
command to check for unresolved dependencies.
Run the following command:
ldd /path/to/your/program
The output will list all libraries needed by the program, and any missing libraries will be marked as “not found.”
Step 8: Reinstall or Recompile the Program
If you’re still encountering issues, it might be that the program was compiled incorrectly and isn’t properly linked to the library. In such a case, you may need to recompile or reinstall the program.
Here’s an example of how you can do that:
- If the program was compiled from source, configure it to use the correct library path:
./configure --prefix=/usr/local --libdir=/usr/local/lib make sudo make install
Summary of Common Fixes
Issue | Solution |
---|---|
Library not installed | Install it via the package manager. |
Library in a non-standard path | Update LD_LIBRARY_PATH or modify /etc/ld.so.conf . |
Wrong architecture (32-bit vs 64-bit) | Install the correct version (32-bit or 64-bit). |
Broken symlinks | Reinstall the library or fix broken symlinks. |
Still Having Trouble?
If you’ve followed all these steps and are still encountering the error, it could be helpful to provide more details such as the exact error message you are receiving and the operating system or distribution you are using. This will allow for more targeted troubleshooting.