17

I get shared library errors whenever I seem to install software manually. Upon executing echo $LD_LIBRARY_PATH it shows up as.. nothing. I've tried adding /usr/local/lib to a .conf file in /etc/ld.so.conf.d but it seems like it never executes.

This doesn't work, either (quotes or otherwise):

LD_LIBRARY_PATH="/usr/local/lib"
export LD_LIBRARY_PATH
sudo ldconfig -v

The value will be set temporarily, but it will not retain the value if I so much as exit a terminal window. Rebooting does nothing, either.

3 Answers3

7

Add the following to your .bashrc:

vim ~/.bashrc

...
export LD_LIBRARY_PATH=/usr/local/lib

This will let you restart your computer, and still have that path assigned.

Kevdog777
  • 3,224
2

I finally resolved this with an alias:

alias sudo='sudo PATH="$PATH" HOME="$HOME" LD_LIBRARY_PATH="$LD_LIBRARY_PATH"'

Be sure to use single quotes, so that the variables are expanded at the time of invocation, not at the time the alias is defined.

This:

  • preserves HOME (which otherwise gets set to /root)
  • preserves PATH (which otherwise gets set to a 'safe' path in suders)
  • preserves the current value of LD_LIBRARY_PATH (which otherwise gets blanked)

(You can see what things get set to with: sudo bash -c "echo $HOME")

I am working with custom drivers and always have to sudo my test programs to access the driver. I don't want to install test versions of libraries in the system area, so I use LD_LIBRARY_PATH to setup a specific test directory as needed. I cant just set a fixed LD_LIBRARY_PATH, I need to be able to change it and keep the current setting. Preserving PATH and HOME gives me access to my work environment - scripts and directory structure.

This alias avoids having to grant blanket permissions in sudoers... and there is apparently no workaround for LD_LIBRARY_PATH regardless of sudoers settings anyway. It does not work sudo inside of scripts, but those can be hardcoded as needed.

vapier
  • 150
Alcamtar
  • 131
1

On Red Hat Enterprise Linux (RHEL) 6, /etc/ld.so.conf contains include ld.so.conf.d/*.conf. Without this line, items in /etc/ld.so.conf.d/*.conf would never be parsed.

To see which libraries / directories ldconfig is parsing

ldconfig -v 

Print current version number, the name of each directory as it is scanned, and any links that are created.

Kevdog777
  • 3,224
pyther
  • 368
  • Yeah, I checked /etc/ld.so.conf earlier as I was curious what it contained. It did have the include line. – Dissident Rage Dec 03 '14 at 15:15
  • Running ldconfig -v might give you an idea why the library isn't being included. You can run ldconfig -p to print the libraries and directories that are in the current cache file. – pyther Dec 03 '14 at 15:22