Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Ubuntu This forum is for the discussion of Ubuntu Linux.


  Search this Thread
Old 07-10-2012, 05:34 AM   #1
LQ Newbie
Registered: May 2010
Posts: 24

Rep: Reputation: 0
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?
Old 07-10-2012, 05:43 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734
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??
1 members found this post helpful.


environment variable, root

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
setting Environment variables? muby Linux - Newbie 5 10-02-2007 05:21 AM
Setting and getting environment variables??? Sulman Shah Fedora 2 12-13-2006 06:33 PM
Setting Environment Variables farzan Linux - Newbie 2 08-07-2004 09:13 AM
setting environment variables jayjoh Linux - Newbie 9 07-12-2004 12:35 PM
setting environment variables rezza Linux - Distributions 2 04-09-2003 08:21 AM

All times are GMT -5. The time now is 10:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration