15

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Dissident Rage
  • 363
  • 2
  • 3
  • 10
  • Try adding it to `~/.bashrc` – Kevdog777 Dec 03 '14 at 14:32
  • possible duplicate of [How to make \`sudo\` preserve $PATH?](http://unix.stackexchange.com/questions/83191/how-to-make-sudo-preserve-path) – muru Dec 03 '14 at 14:35
  • It's not a duplicate; the question is irrelevant and the answer doesn't work. – Dissident Rage Dec 03 '14 at 14:52
  • 1
    It's a [bad Idea to install software from source on a binary system](http://unix.stackexchange.com/questions/152258/using-awesome-window-manager-on-centos-7/152809#152809)!!! Use your Package Manager, [unless there is no other way](http://unix.stackexchange.com/questions/169255/how-to-build-dnscrypt-plugins/169272#169272) – eyoung100 Dec 03 '14 at 14:53
  • 1
    Yes, let me use *broken software from a year ago* instead of allowing me to update it to test if anything has changed for the better. – Dissident Rage Dec 03 '14 at 14:55
  • First of all, before blowing up at me, read my first link, the consider reading the second, since you want the package. Third, why don't you tell me what you are trying to update, and I'll help you do it properly. Exporting `LD_LIBRARY_PATH` is also bad, because if not done properly, you break the path your binary packages expect. This problem is your 3rd comment to Kevdog777 – eyoung100 Dec 03 '14 at 15:00
  • I'm being very cautious and meticulous about the changes being made. I'm only considering making this change because it's documented *everywhere* as being a generally good idea. As for what's being updated: http://unix.stackexchange.com/questions/171270/openconnect-not-resolving-hostnames – Dissident Rage Dec 03 '14 at 15:11

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,194
  • 18
  • 43
  • 64
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
  • 5
Alcamtar
  • 131
  • 4
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,194
  • 18
  • 43
  • 64
pyther
  • 328
  • 1
  • 6
  • 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