14

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?

techraf
  • 5,831
  • 10
  • 33
  • 51
linquize
  • 969
  • 2
  • 9
  • 9

2 Answers2

24

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.)

derobert
  • 107,579
  • 20
  • 231
  • 279
  • @bahamat I'm guessing due to an edit overlap, you wound up taking out a paragraph from my answer. I'll add it back.. – derobert Aug 29 '12 at 15:42
  • Nope, I just removed it because "you don't need to" already sums it up and it's much more concise. – bahamat Aug 29 '12 at 15:50
  • @bahamat Check the edit log, http://unix.stackexchange.com/posts/46620/revisions ... I think what happened is that we both hit the edit link, then I submitted my change (the extra paragraph), then you submitted your change (which of course didn't include the extra paragraph). Seems like StackExchange ought to detect this and warn loudly, but apparently not... – derobert Aug 29 '12 at 15:51
  • No, I just explicitly removed that paragraph because I thought it was unnecessary. I didn't make any other changes. Our edits were 6m apart and the one that came after me was 12m later. It wasn't a collision. – bahamat Aug 29 '12 at 15:57
  • @bahamat Ah, leaving an edit comment would have cleared up the confusion... – derobert Aug 29 '12 at 16:05
  • But depending on what is actually in the target directory this could potentially cause a lot of problems. – Keith Aug 30 '12 at 00:19
  • @Keith that's true, though I think it'd be no more than would be caused by setting LD_LIBRARY_PATH system-wide. I'll add in a word of caution. – derobert Aug 30 '12 at 15:20
  • This doesn't work. At all. LD_LIBRARY_PATH will still always be blank. – Dissident Rage Dec 03 '14 at 14:20
  • @DissidentRage That's the point, the environment variable doesn't need to be set to add a directory to the system library path. – derobert Dec 03 '14 at 15:10
3

You can add every path in the file in /etc/ld.so.conf.d then run :

ldconfig -v 

Then load them.

PersianGulf
  • 10,728
  • 8
  • 51
  • 78