5

In order to export variables permanently, we can write the export command in the following files:

~/.profile
~/.bash_profile
/etc/profile 

In my case, ~/.bash_profile does not exist, and therefore I export the variable in the other two files:

export country=UK

The problem I have now is that the variable I defined (country) is still unknown for the system. I was wondering what I should do next.

2
  • 1
    If you define variables in ~/.profile or ~/.bashrc (or whatever shell you are using. It is not always bash) then you set those only for yourself. They only get executed when you log in. (and only after you log in, if you changed those and did not logout and back in then they will not yet have taken effect). The same holds for /etc/profile, though that will affect all users. -- However what I am missing is your goal. Did you just choose a random example (country), or do you want to set a locale?
    – Hennes
    Dec 17, 2012 at 12:30
  • possible duplicate of How do I set environment variables?
    – hhlp
    Dec 17, 2012 at 14:07

2 Answers 2

4

profile is only read when you login, have you tried a login shell bash -login,bash -,logging out and then back in or just plain old rebooting?

You can use .bashrc if want it every time you spawn a shell.

1
  • @Hennes Your comment is overkill bash -login is already mentioned.
    – squareborg
    Dec 17, 2012 at 12:40
2

If you want these variables to be available for all the users on the system, you can define them in /etc/environment.

You must log in to answer this question.

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