LD_LIBRARY_PATH is an environment variable on Unix systems that is frequently misused.
An environment variable is a value that influences the behavior of certain computer processes.
Although environment variables are developed for UNIX, they are also used on Windows and Linux.
A lot of programmers apply the variable incorrectly, which can cause issues.
In this guide, you’ll learn what is LD_LIBRARY_PATH, how to use it, and issues with the variable on Unix/Linux/Windows.
What is LD_LIBRARY_PATH?
LD_LIBRARY PATH is an environment variable that sets the path which the linker looks into when linking dynamic or shared libraries.
In other words, it tells the link loader where to look for the dynamic shared libraries.
It includes a colon-separated list of paths and the linker gives priority to them over standard library paths.
In most cases, you need to set “java.library.path” on a JVM command line.
How to use LD_LIBRARY_PATH
LD_LIBRARY_PATH has 3 main usages.
Firstly, it can be used to test new versions of a shared library with a compiled app.
Secondly, it can be used to re-locate shared libraries to conserve old versions.
Lastly, you can create a relocatable environment for large applications so that they don’t depend on system libraries.
Here’s an example of its usage:
$ export LD_LIBRARY_PATH="/list/of/library/paths:/another/path"
Issues with LD_LIBRARY_PATH
There are 3 main problems with LD_LIBRARY_PATH.
Firstly, it compromises security as a hacker can access your application to load a shared library with malicious code.
Secondly, it decreases the performance of your applications if the path has a lot of directories because failed calls will increase.
Lastly, LD_LIBRARY_PATH will cause an application to load a shared library that’s not linked against which might not be compatible with the original version.