How to Fix "Cannot Open Shared Object File" Error in Linux
The "cannot open shared object file: No such file or directory" error appears when a program cannot find a required shared library (.so file). This is extremely common when compiling software from source or running proprietary applications. Here is how to fix it.
Fix 1: Identify the Missing Library
The error message tells you exactly which library file is missing. Note the full filename, for example, libssl.so.1.1. Different Linux distributions may have different package names for the same library. Search for the missing library with apt-cache search libssl to find available packages containing similar libraries.
Fix 2: Install the Missing Library Package
Once you know the library name, find which package provides it. For Ubuntu/Debian, install apt-file with sudo apt install apt-file, then run apt-file update and apt-file search libssl.so.1.1. The output shows which package contains the missing library. Install it with sudo apt install packagename. Common missing libraries include libssl, libcurl, libncurses, and libgtk.
Fix 3: Add the Library Path
If the library exists but the program cannot find it, you need to add its directory to the library path. Find the library with find /usr -name "libssl.so.*". Then set the path temporarily with export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH. To make it permanent, add this line to your ~/.bashrc file.
Fix 4: Update the Library Cache
After installing a new library, you may need to update the library cache. Run sudo ldconfig to refresh the system library cache. This command creates the necessary links and cache for shared libraries. If you installed a library to a custom location, add the path to /etc/ld.so.conf and run ldconfig.