And as you are asking about "system wide":
Configuration files located in the /etc
directory apply to all users on the system. For /etc/bash.bashrc
this would mean to all and everything that's using the "Borne Again SHell" aka Bash on that machine. Even if you're the only human using it, there could be "technical users" affected (simply take a look into the /etc/passwd
and check how often the term "/bin/bash" is stated there -- or use grep bash /etc/passwd | wc -l
, which should give you that number directly (meaning: "grab" all lines containing the string "bash" from the file "/etc/passwd", and send the results ("|") to the command "wc" (word count) to count the lines ("-l").
So for your user, it is much safer to modify ~/.bashrc
instead (meaning the file ".bashrc" -- with a leading dot, yes -- in your home-directory, e.g. /home/ankur/.bashrc
), which then just affects your user and leaves everything else alone. Files in /etc
should only be changed if system-wide changes are really intended.
Besides: Both configurations will be used if they exist. First, the system-wide file (here: /etc/bash.bashrc
) is read and "sourced" (it's settings applied to the current session), and then the users /home/username/.bashrc
is handled the same, and thus can add to or even change/overwrite settings from the global /etc/bash.bashrc
file.
/etc/environment
sets environment variables at login, regardless of your shell./etc/bash.bashrc
(and~/.bashrc
) executes (and may set environment variables during that execution) every time a bash shell is opened. But if your login shell is not bash, or you open a different shell, it is not executed. So, if you change settings in /etc/environment and then open a new shell, you don't get the new values. If you change settings and login viassh localhost
of course that's a new login, so you'll get the new values. – Auspex Aug 19 '22 at 14:45