LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (http://www.linuxquestions.org/questions/ubuntu-63/)
-   -   Setting persistent environment variables for root user (http://www.linuxquestions.org/questions/ubuntu-63/setting-persistent-environment-variables-for-root-user-4175415870/)

AlexFr 07-10-2012 06:34 AM

Setting persistent environment variables for root user
 
To create persistent environment variables, I add the script file to /etc/profile.d directory, for example:
Code:

# my script
export MY_VAR=var_value

This works properly for current user:
Code:

alex@alex-64:~$ echo $MY_VAR
var_value

Now I need the same environment variables for the root user, but /etc/profile.d script doesn't work for root:
Code:

alex@alex-64:~$ echo $MY_VAR
var_value
alex@alex-64:~$ sudo su
root@alex-64:/home/alex# echo $MY_VAR

root@alex-64:/home/alex#

How can I set the same variables for the root?

pixellany 07-10-2012 06:43 AM

when you issue "su", you take on root privileges, but you keep your user environment. Use "su -" to have the root environment.

Also, I'm not sure when that script runs---for sure at boot time, but when loggin in??


All times are GMT -5. The time now is 06:13 PM.