How do I set persistent environment variables for root?

sudo does not normally preserve local environment variables. You should use it with the -E switch to do so, i.e. sudo -E su will preserve $MYVAR for root.

Alternatively, to create persistent variables that are truly system-wide, you should set them in /etc/environment.


Defaults env_reset in /etc/sudoers will reset root's PATH defined by /etc/environment.

You could modify it to Defaults !env_reset to disable resetting or add:

Defaults secure_path="my/custom/path:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin

Like the process you define your own environment variable, for example by editing '~/.bashrc', you can define root's environment variable by editing '/root/.bashrc'.