Home » How-To » What is LD_LIBRARY_PATH?

What is LD_LIBRARY_PATH?

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"
$ ./program

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.

Further reading

How to Fix “python: can’t open file ‘manage.py’: [Errno 2] No such file or directory”

How to Fix “TypeError: ‘type’ object is not subscriptable”

How to Fix “Object of Type ‘int’ has no len()”

About the author

Lim How Wei

Lim How Wei is the founder of followchain.org, with 8+ years of experience in Social Media Marketing and 4+ years of experience as an active investor in stocks and cryptocurrencies. He has researched, tested, and written hundreds of articles ranging from social media platforms to messaging apps.

Lim has been quoted and referenced by major publications and media companies like WikiHow, Fast Company, HuffPost, Vice, New York Post, The Conversation, and many others. One of his articles about the gig economy was quoted by Joe Rogan who hosts The Joe Rogan Experience (arguably the most popular podcast in the world), in the This Past Weekend podcast by Theo Von.

In his free time, Lim plays multiple games like Genshin Impact, League of Legends, Counter-Strike, Hearthstone, RuneScape, and many others. He creates guides, walkthroughs, solutions, and more on games that he plays to help other players with their progression.