How to Fix ‘cannot open shared object file: No such file or directory’ in Ubuntu

Launching compiled binary executables, proprietary development tools, or third-party software on Ubuntu only to be stopped by the error “error while loading shared libraries: libsomething.so.X: cannot open shared object file: No such file or directory” indicates a dynamic linker failure. In Linux, dynamically linked programs do not embed every functional library directly inside the binary file; instead, they rely on the dynamic linker (ld.so) to load required shared object (.so) libraries into memory at runtime. This error occurs when the required library is not installed, installed under an alternate architecture (32-bit vs 64-bit), or stored in a directory missing from the dynamic linker cache.

Identify Missing Shared Libraries with ldd

The ldd utility prints all shared object dependencies required by a program alongside their resolved filesystem paths.

  1. Open a terminal window (press Ctrl + Alt + T).
  2. Run ldd against the problematic binary executable:
    ldd /path/to/your/program
  3. Review the output list. Any dependency that fails to link will be flagged with:
    libexample.so.1 => not found
  4. Note the exact name of the missing library file.

Find and Install the Package Providing the Library with apt-file

The standard Ubuntu APT repository contains tens of thousands of packages. Determining which specific package provides a particular .so file requires the apt-file indexing tool.

  1. Install apt-file if it is not already present:
    sudo apt update && sudo apt install apt-file -y
  2. Update the package contents index cache:
    sudo apt-file update
  3. Search for the missing shared object file:
    apt-file search libexample.so.1
  4. Review the search results to find the corresponding package name (e.g. libexample1).
  5. Install the package using apt:
    sudo apt install libexample1
  6. Run your program again to confirm successful execution.

Update the Dynamic Linker Cache with ldconfig

If you compiled or manually installed a library into /usr/local/lib or a custom directory, the dynamic linker will not recognize the new files until the cache is refreshed.

  1. Check if the library file exists in standard directories:
    sudo find / -name "libexample.so*" 2>/dev/null
  2. If the file is located in /usr/local/lib, verify that this directory is included in the dynamic linker configuration:
    cat /etc/ld.so.conf.d/*.conf
  3. If absent, create a custom configuration entry:
    echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/custom-libs.conf
  4. Rebuild the dynamic linker cache bindings:
    sudo ldconfig

Export LD_LIBRARY_PATH for Standalone Applications

For standalone applications, proprietary games, or Anaconda environments where libraries reside inside a dedicated project subfolder, configuring the LD_LIBRARY_PATH variable directs the dynamic linker to custom directories.

  1. Temporarily append the application library path before running the binary:
    export LD_LIBRARY_PATH=/opt/myapp/lib:$LD_LIBRARY_PATH
    ./myapp
  2. To make this change permanent for your user account, add the export line to your ~/.bashrc file:
    echo 'export LD_LIBRARY_PATH=/opt/myapp/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
    source ~/.bashrc

Enable Multiarch Support for 32-Bit Libraries

If you are attempting to run older 32-bit binaries (such as legacy Wine applications or retro game engines) on a 64-bit Ubuntu installation, 64-bit libraries cannot fulfill 32-bit linking requirements.

  1. Enable the 32-bit (i386) architecture on your system:
    sudo dpkg --add-architecture i386
    sudo apt update
  2. Install the 32-bit variant of the missing library (appending :i386 to the package name):
    sudo apt install libexample1:i386
  3. Run the binary again. The 32-bit dynamic linker will load the i386 shared object cleanly.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.