How to export LD_LIBRARY_PATH to all users and system services

dynamic-loadingenvironment-variableslibrariespath

I want to export LD_LIBRARY_PATH to system services and all users.
System services are run before login, so .bashrc is not applicable.

How to achieve this?

Best Answer

You don't need to. Add the directory to /etc/ld.so.conf or a new file in /etc/ld.so.conf.d/, depending on distro.

After that, you must run (at least on Redhat) ldconfig as root.

As a word of caution, you need to be careful which libraries you add to the system shared library path (via the environment, ld.so.conf, or putting in /usr/local/lib). In particular, you beware of two different versions of the same library with the same soname. E.g., if you have a libfoo.0.1 (soname libfoo.0) installed via dpkg/rpm/etc., you don't want a libfoo.0.2 (also soname libfoo.0) in your custom library directory.

(It's actually not that easy to pull off a system-wide environment variable. You can get most user logins with /etc/environment. Scripts will depend on your init system, but (for example) with sysv init on Debian, you could put it in /etc/default/rcS. Anything run straight out of inittab, well, I don't think you can.)

Related Question