views:

91

answers:

4

Where Linux/Unix environment variables are kept? How can I add my own environment variable and make it persistent, not only within currently running script?

+2  A: 

you can add them in your profile, eg ~/.bash_profile. global profile is usually located in /etc. eg /etc/profile. Take a look also at /etc/profile.d directory if you have it.

ghostdog74
I don't see /etc/profile, but I see /etc/profile.d which contains gvfs-bash-completion.sh and speechd-user-port.sh files. What exactly should I do to add environment variables for all users?
Alex Farber
those in `/etc/profile.d` are custom profiles. For all users, if you don't have `/etc/profile` then create it.
ghostdog74
+1  A: 

To see the env variable use printenv command

To set a new variable you can use ~/.bash_rc file

export new_variable = 10

Thats all you have to do. It will accessible for shells

Abhi http://codeviews.com

Abhijith
Thank you. Do you mean ~/.bashrc file? What about setting environment variable for all users?
Alex Farber
No spaces around `=`. `export new_variable=10` or it won't work.
SF.
+1  A: 

Are you looking for the export keyword?

More information:

Anders Abel
+1  A: 

Add export statements to ~/.bash_login

Amarghosh
I don't see ~/.bash_login file. Can I create it? What is the difference between ~/.bash_login and ~/.bashrc?
Alex Farber
@alex You can create one. bash_login runs for login shells and bashrc for interactive shells - check the man page for details.
Amarghosh