Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to set an environment variable system wide.

Following the ubuntu site recommendations , I set it up to my /etc/environment file.

The thing is when I log out and log in again, I have to source it if I want my environment variable to be set. What am I missing ?

Thank you,

Content :

MYVAR="/home/user/mypath"
share|improve this question
    
Can you show the exact content of /etc/environment file? And I hope your logout/login sequence does not correspond to "close terminal / open terminal". –  enzotib Jul 19 '11 at 10:17
    
What I mean by logout/login is when I ssh myself to a server. I would like the varaible to stay set even when I leave the server. –  Spredzy Jul 19 '11 at 11:28
    
Environment should stay for the ssh session and all of its childs, without the need to source /etc/environment. What do you mean by "when I leave the server"? –  enzotib Jul 19 '11 at 11:37
    
~/.bashrc and ~./.bash_aliases is what your looking for in most cases. These files are read every time you run bash. If you are not using bash then you should have a look a what ever programming you are running and changing its environment at start up. –  nelaar Sep 21 '11 at 11:50
add comment

1 Answer

You can define a variable like pythonpath like this export PYTHONPATH=$PYTHONPATH:/home/chris/my_new_path/ this concatenates the existing data of your variable with the new path.

You can check if your variable is set correctly with echo $MY_VAR and you can check your environment variables with the command printenv everything from a console.

You can add the export command to your ~/.bashrc or ~/.bash_aliases file in order not to execute it manually every time you log in.

share|improve this answer
2  
The user ask for a "system wide" variable. Also, .bash-aliases, though it will work, is not conceptually the place to use. –  enzotib Jul 20 '11 at 5:41
    
Debian suggests a policy against wide system variables, there is a workaround to make things more elegant: debian.org/doc/debian-policy/ch-opersys.html#s9.9 –  topless Jul 20 '11 at 11:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.