2 of 6
added 285 characters in body
zetah
  • 9k
  • 9
  • 47
  • 69

Environment variables when run with 'sudo'

As example to my question, my ~/.bashrc file contains this lines:

> export LD_LIBRARY_PATH=/opt/intel/mkl/lib/ia32:$LD_LIBRARY_PATH
> export LD_PRELOAD=/opt/intel/mkl/lib/ia32/libmkl_core.so

so that Numpy (Python) could find libraries that it needs to run, as it's build with MKL and Intel compilers. This workflow isn't the best, but that's another story.

My question is how can I pass arbitrary variables (like those in .bashrc) when I run program with 'sudo' (but not root)?

Currently, if I run:

sudo python -c "import numpy"

I get error:

ImportError: libimf.so: cannot open shared object file: No such file or directory

Some suggestions as sudo -i or sudo -E does not change anything here. I'm on Ubuntu 11.04

Thanks in advance


Edit:

I can't answer my question (not enough points :D ) but I'll comment here, in a hope that there are other Linux newbies wondering about 'sudo' traps.

This works for me (~/.bashrc):

alias sudo='sudo env PATH=$PATH VAR1=SOME_VALUE VAR2=SOME_VALUE...'

PS. although this can't work with gksudo ;)

zetah
  • 9k
  • 9
  • 47
  • 69