5

I've tryed to add environment variable in terminal:

loom@loom:~$ export DOOM=/home/loom/doom/
loom@loom:~$ echo $DOOM 
bash: /home/loom/doom/: Is a directory

Then I've closed terminal and reopened it. However, there isn't $DOOM variable now. How to add environment variable via terminal?

Oleg Svechkarenko
  • 153
  • 1
  • 1
  • 6

1 Answers1

8

Environment variables set like this are only stored temporally. When you exit the running instance of bash by exiting the terminal, they get discarded. To save them permanentally, write the export x=y commands into /etc/profile (for all users) or ~/.profile (for yourself) Do this by editing/creating (?) the file using your preferred text editor (as root for /etc/profile). Examples:

sudo nano /etc/profile
gedit ~/.profile
# etc... kate, leafpad, vim, whatever you want to use
s3lph
  • 14,118
  • 11
  • 57
  • 82
  • 2
    Better to use `~/.bashrc` file instead `~/.profile` file! – Radu Rădeanu Dec 24 '13 at 15:06
  • What's the difference? – s3lph Dec 24 '13 at 15:11
  • Please see [.profile vs. .bash_profile vs. .bashrc](http://serverfault.com/questions/261802/profile-vs-bash-profile-vs-bashrc) – Radu Rădeanu Dec 24 '13 at 15:17
  • @RaduRădeanu: I don't understand what you base your claim on that ~/.bashrc is better than ~/.profile. Environment variables set in ~/.bashrc are not available in graphical shells. https://help.ubuntu.com/community/EnvironmentVariables#Persistent_environment_variables – Gunnar Hjalmarsson Dec 24 '13 at 22:36