-   Ubuntu (
-   -   Setting persistent environment variables for root user (

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:

# my script
export MY_VAR=var_value

This works properly for current user:

alex@alex-64:~$ echo $MY_VAR

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

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


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 08:11 PM.