3

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"
4
  • 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, 2011 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, 2011 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, 2011 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.
    – nelaaro
    Sep 21, 2011 at 11:50

1 Answer 1

1

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.

2
  • 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, 2011 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, 2011 at 11:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .