Reputation: 1703
I'm Mac user.
I want to set PYTHONPATH env for root. so
$ sudo su -
# vi ~/.profile
and add to file 'export PYTHONPATH=/mypythonlib'
then
# env
I can see this line
PYTHONPATH=/Users/simpnet2/projects/meiji/src/hershey
but..
when I use sudo command, cannot find that
$ sudo env
.. there's no PYTHONPATH
My program has to run with sudo command and needs PYTHONPATH
.
Upvotes: 11
Views: 41017
Reputation: 471
Well, in other Linux system, it is also right that 'sudo' does not use local environment variable. But you can declare the temporary environment variable along with 'sudo' command.
For example, in your case, you can add 'PYTHONPATH=/mypythonlib' in your command 'sudo env', and the final command is:
sudo PYTHONPATH=/mypythonlib env
You can also read this article: Using sudo. You can see how 'sudo' keep or ignore user-defined environment variables.
Upvotes: 1
Reputation: 111
In the case of logging in as a normal user and invoking "su - root" I found that Mac OS 10.8.5's bash was ignoring .profile and .bash_profile; I was unable to change root's $PATH by editing those files. What did work was editing /etc/paths. After exiting the root shell and entering again with "su - root" the new path was present.
Upvotes: 0
Reputation: 369
You can make PYTHONPATH visible to sudo be editing your sudoers file. Notice you should ONLY do this through visudo as explained here.
Upvotes: 6
Reputation: 230
As of 10.8.5, putting my environment statements in the .profile path in the home of the root user (/var/root) worked. after quitting bash and coming back to the root user prompt with 'su -', I could see my new path, etc. with the 'env' command and my MacPorts installationw orking correctly.
MacBook-Pro:~ root# cat /var/root/.profile export MANPATH=/opt/local/share/man:$MANPATH export PATH=/opt/local/bin:/opt/local/sbin:$PATH MacBook-Pro:~ root# which port /opt/local/bin/port
Upvotes: 1
Reputation: 2603
If you use sh try /etc/profile
, bash try /etc/bashrc
and if you use zsh try /etc/zshenv
.
Upvotes: 10
Reputation: 37909
You should try sudo -i
which will simulate logging in as root
and source the ~root/.profile
.
Upvotes: 5