I tried to create an environment variable in my ~/.bashrc file as follows:


After doing some troubleshooting it appears bash isn't picking up the new environment variable at all. I tried setting it in ~/profile but that hasn't worked either. (I edited both files under sudo) What am I doing wrong?

  • man bash and take a look at the INVOCATION part. This describes in details what files are used when. – pawel7318 Aug 24 '17 at 13:46
  • 3
    Why did you use sudo to edit these files? They belong to your user, not to root. – Kusalananda Aug 24 '17 at 13:58
  • 2
    Maybe you hadn't reloaded your shell? – Jeff Schaller Aug 24 '17 at 13:59
  • To narrow the problem: Is the variable set after sourcing . ~/.bashrc? – Philippos Aug 24 '17 at 14:03
  • Your title (correctly) references ~/.profile but your question body says ~/profile. In which one did you actually put the environment variable? – roaima Aug 24 '17 at 16:05

Editing the file is not enough. You need to source that file. This is done usually when you start bash, but if you edited the file, you can force to read the file with:

source ~/.bashrc

Note: some systems could restrict what file is parsed at start of bash (e.g. if the file is writable by "other", or just different requiring different files, but AFAIK it is not often done, but on special devices)


You wrote that you edited the file with sudo. this could be a problem: if your user cannot read that file, the file is ignored. .bashrc is read as your user. But also this should not be a normal case: the files should already exists, and only bad editors will change permission of edited file.


Answer: I forgot to put true in quotes.

  • 4
    No, that was not the issue. It ought to have worked without the quotes too. – Kusalananda Aug 24 '17 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.