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?
Asked
Active
Viewed 7,625 times
3
-
http://lowfatlinux.com/linux-environment-variables.html – Arthur Kalliokoski Mar 17 '10 at 08:08
4 Answers
3
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
- 327,991
- 56
- 259
- 343
-
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 F Mar 17 '10 at 08:26
-
1those in `/etc/profile.d` are custom profiles. For all users, if you don't have `/etc/profile` then create it. – ghostdog74 Mar 17 '10 at 09:17
1
To see the env variables use the printenv
command.
To set a new variable you can use the ~/.bash_rc
file:
export new_variable=10
new_variable
will be accessible for all shells.

Marcel Gosselin
- 4,610
- 2
- 31
- 54

Abhijith
- 11
- 1
-
Thank you. Do you mean ~/.bashrc file? What about setting environment variable for all users? – Alex F Mar 17 '10 at 08:24
-
1
1
Are you looking for the export
keyword?
More information:
- Defining a variable with or without export
- http://www.ibm.com/developerworks/library/l-bash.html - section Environment variables.

Community
- 1
- 1

Anders Abel
- 67,989
- 17
- 150
- 217
1
Add export
statements to ~/.bash_login

Amarghosh
- 58,710
- 11
- 92
- 121
-
I don't see ~/.bash_login file. Can I create it? What is the difference between ~/.bash_login and ~/.bashrc? – Alex F Mar 17 '10 at 08:27
-
@alex You can create one. bash_login runs for login shells and bashrc for interactive shells - check the man page for details. – Amarghosh Mar 17 '10 at 09:34