How to fix: ‘cannot open shared object file : No such file or directory’ on Ubuntu

Sometimes, when you try to install a program or a package from its source code, you might end up getting an error which looks like :

“error while loading shared libraries: cannot open shared object file No such file or directory”

In general, if the package shared library name is lib, the error sometimes shows the following :

error while loading shared libraries: lib.so.X: cannot open shared object file: No such file or directory

Where X is a number.

These dynamically generated shared libraries, which are required by executables, are stored under /lib or /usr/lib directories.

The command below can help find out the libraries that are needed for a given executable :

ldd nw

As a quick workaround, you could try to fix the issue by running ldconfig command below :

sudo ldconfig -v

Now at runtime, the system would need to locate the ‘.so’ corresponding library file since the package or the program is linked with the library shared version.

To locate the library, invoke the command below :

sudo find / -name lib_file.so.x

or you could use apt search command. Jot down the path in which the lib_file.so.x is found, path_to_so_file.

Read: How to find the largest files on Linux

To include the folder in which the library is installed, the shell variable LD_LIBRARY_PATH has to be provided.

If LD_LIBRARY_PATH is not defined (run echo $LD_LIBRARY_PATH to find out), you could set it using the command (in the Bash shell) :

LD_LIBRARY_PATH=/usr/local/lib

Now using the path of the .so file that you found above, path_to_so_file, run the commands below :

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:path_to_so_file

export LD_LIBRARY_PATH $ ./your_package

You can find out more about shared libraries here.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Nikolaus Oosterhof

Nikolaus holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply