Ubuntu – difference between bash.bashrc and /etc/environment file

bashbashrccommand lineenvironment-variables

Till date I used to set my environment variables in the bash.bashrc file. Recently I was told to use the /etc/environment file. Well, both work fine.

So, what is the difference between them?

I googled this and I found "bashrc is used for particular user and environment, system wide". What is meant by system wide here? /etc/bash.bashrc is also applying changes system wide I guess. Correct me if I am wrong. Any kind of help will be appreciated..

Best Answer

One difference is that /etc/environment contains only variable definitions and doesn't appear to go through any sort of variable expansion/interpolation. Thus, you can't reference variables in definitions. This for instance won't work:

A="else"
B="something $A"

B will literally be something $A, not the expected something else.

See this question.

By the way, the answer you found through Google appears to be referring to a user's ~/.bashrc, rather than the system-wide /etc/bash.bashrc. That may be causing your confusion.