In Linux, the predefined paths for shared objects (.so) are /lib/ and /usr/lib/. During normal usage this is OK but sometimes it's necessary to specify other additional paths. There are several way to do this task.

Environment Variable

The most common way is to define an environment variable in the shell:

$ export LD_LIBRARY_PATH=/path/to/shared/objects

This operation must be done in every new shell/terminal emulator before starting the process that needs the shared objects located there. To avoid this, you can insert the export in your .bashrc or .profile file (located in your home directory): in this way the variable is set every time you open the terminal.

The Dynamic Linker Configuration File

Sometimes you need a shared object to be called from daemons or processes run by various users. The solution is the file /etc/ld.so.conf. In this file you can add all the paths where shared object should be searched.

In Debian-based distros (like Ubuntu), this file only include the following line:

include /etc/ld.so.conf.d/*.conf

This means that you don't have to change this file. Instead, you can add your paths to a file with extension .conf located in the directory /etc/ld.so.conf.d/. When needed, the dynamic linker will search the files in this directory to locate the paths of the shared objects.

Security Notes

Pay attention! Adding directories not owned by root (or for which users other than root have writing privileges) can be a security breach, because it can lead to the execution of arbitrary code.


This post has been updated after its initial publication. Last change made on 2016/11/11.