8

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.

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.

  • 2
    That's fine for one user. What about for all users? – Dissident Rage Dec 3 '14 at 14:52
  • 2
    @DissidentRage: add the same to /etc/bash.bashrc – JdeHaan Dec 3 '14 at 14:56
  • I'm going to mark this as the answer because this works for the given scope. What can I do about the files that are clearly not being run in /etc/ld.so.conf.d? – Dissident Rage Dec 3 '14 at 14:59
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.

  • Yeah, I checked /etc/ld.so.conf earlier as I was curious what it contained. It did have the include line. – Dissident Rage Dec 3 '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 3 '14 at 15:22
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.