How to set environment variable for root user

I am a Mac user.

I want to install PYTHONPATH env for root. so

$ sudo su -
# vi ~/.profile

and add to the file 'export PYTHONPATH = / mypythonlib'

then

# env

I see this line

PYTHONPATH=/Users/simpnet2/projects/meiji/src/hershey

and..

when i use sudo command i can't find that

$ sudo env

.. no PYTHONPATH

My program should work with the sudo command and needs to PYTHONPATH.

+5
source share
6 answers

If you use sh try /etc/profile, bash try /etc/bashrc, and if you use zsh try /etc/zshenv.

+6
source

PYTHONPATH sudoers. , visudo .

+5

sudo -i, root ~root/.profile.

+2

10.8.5, .profile root (/var/root). bash "su -", .. "env" MacPorts .

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
+1

, Linux , "sudo" . "sudo" .

, 'PYTHONPATH =/mypythonlib' 'sudo env', :

sudo PYTHONPATH=/mypythonlib env

: sudo. , "sudo" .

+1

When I logged in as a regular user and called "su-root", I found that Mac OS 10.8.5 bash ignores .profile and .bash_profile; I could not change root $ PATH by editing these files. What editing / etc / paths worked. After exiting the root shell and entering again using "su-root", a new path appeared.

0
source

All Articles