Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Reading the man pages I expected sudo -E to pass all environment variables to the subshell, but I am not getting the expected results.

As expected, awesome:

$ export LD_LIBRARY_PATH=/home/mmendez/toolchains/x86-destdir/usr/lib/
$ env | grep LD

More awesomeness:

$ env -i LD_LIBRARY_PATH=/tmp/no/where env | grep LD

Not what was expected:

$ env -i LD_LIBRARY_PATH=$LD_LIBRARY_PATH sudo -E /usr/bin/env | grep LD
$ env -i LD_LIBRARY_PATH=/tmp/no/where sudo -E /usr/bin/env | grep LD

So, how can I get sudo -E to pass LD_LIBRARY_PATH, without editing /etc/sudoers?


According to How do I make sudo preserve my environment variables? the OP indicates that the shell may play a role in conjunction with !env_reset. I am running Arch Linux and the default shell is BASH. Once again, I do not want to edit /etc/sudoers, is it possible?

share|improve this question
up vote 4 down vote accepted

Certain environment variables, including LD_LIBRARY_PATH or HOSTALIASES (full list is in sysdeps/generic/unsecvars.h), are automatically unset by glibc when executing a privileged program (i.e. with the setuid bit or with filesystem capabilities). This is a security feature, since otherwise users could load their own libraries into su or sudo and trick them into accepting any password.

You will need to use sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH yourcommand in order to pass the variable to commands run via sudo.

share|improve this answer
Ahh, ok thanks. – mmlb Jan 31 '13 at 17:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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