Mittwoch, 16. Februar 2011

sudo doesn't export LD_LIBRARY_PATH

Sometimes it is desired that you put your own shared libraries into an own directory to keep your system's libraries paths clean. There's nothing to say against it. For this reason, an environment variable can be defined, which points to your library path: LD_LIBRARY_PATH.
Normally you define your path for example in /etc/profile and it is then available for every user.
However, you can find yourself surprised, that calling your application as user root by using the 'sudo' command will fail. The reason is quite simple: The sudo command doesn't export your LD_LIBRARY_PATH!

This can be proven by doing a 'sudo printenv'. Also doing a sudo -V as superuser will show you, that every environment variable beginning with 'LD_*' will not be forwarded.

The only workaround I found for this is the use of the sudo command with an alias.

In your ~/.bashrc file add following alias:

# because sudo doesn't export LD_LIBRARY_PATH for our apps
alias sudo='sudo env LD_LIBRARY_PATH=/usr/local/lib/your_path'

Save this file and source it. Afterwards your sudo command can be used conveniently.

Keine Kommentare: