Linux – Is it normal that LD_LIBRARY_PATH variable is missing from an environment

environment-variablesldlinux

I have found by coincidence that on my Debian Jessie there is no LD_LIBRARY_PATH variable (to be exact printenv | grep LD shows nothing related to linker and echo "$LD_LIBRARY_PATH" shows also nothing).

This is the case in x terminal emulator (which might clear it due to setgid) as well as in basic terminal (Ctrl+Alt+F1).

I know that LD_LIBRARY_PATH may be considered bad so Debian may block it somehow, but on the other hand there are a few files in /etc/ld.so.conf.d/ that contains some directories to be added to LD_LIBRARY_PATH. None of my rc files (that I know of) mess with LD_LIBRARY_PATH either.

Why I don't see an LD_LIBRARY_PATH variable?

Best Answer

Yes, it is normal that you don't have any explicit LD_LIBRARY_PATH. Read also ldconfig(8) and ld-linux(8) and about the rpath. Notice that ldconfig updates /etc/ld.so.cache, not the LD_LIBRARY_PATH. Sometimes you'll set the rpath of an executable explicitly with -Wl,-rpath,directory passed to gcc at link time.

If you need a LD_LIBRARY_PATH (but you probably should not), set it yourself (e.g. in ~/.bashrc).

If you need system wide settings, you could e.g. consider adding /usr/local/lib/ in /etc/ld.so.conf and run ldconfig after installation of every library there.

AFAIK $LD_LIBRARY_PATH is used only by the dynamic linker ld-linux.so (and by dlopen(3) which uses it) after execve(2). See also ldd(1).

Read Drepper's How To Write Shared Libraries for more.

Related Question