Linux /etc/bash.bashrc versus /etc/profile

The most common place that people add system-wide environment variables on Linux is in /etc/profile. However, this requires that you log out and back in again (or start another session) for these changes to take effect. Whilst this is acceptable practise for most Linux desktop developers, I find it a little tedious when working from the Linux command-line.

So, after a little probing, I discovered that you can also make system-wide changes in /etc/bash.bashrc file but can use these immediately by simply invoking a new bash session (by typing bash at the same command prompt).

Of course if you have desktop applications that require the new settings then you will still have to log out and back in again as before but, if like me, you work a lot from the command-line, then you have the added benefit of being able to use the new settings immediately.


3 thoughts on “Linux /etc/bash.bashrc versus /etc/profile”

  1. Hi James,
    the downside of that is that it only applies to Bash. Any graphical applications that you start would not have the variables available to them (even if you restart). If you run Bash with a “-ls” (login shell, I believe) parameter it should run the /etc/profile

  2. Excellent!

    I did wonder about this on the way home last night as I wasn’t entirely convinced of the long-term flexibility of a file named bash.bashrc in a sysem-wide scale.

    I just tried the “bash -ls” command it worked a treat. So, the best of both worlds is to stick with the /etc/profile but use “bash -ls” from the command-line if you want to use the changes immediately.

    Of course you still need to log out and in again for graphical/desktop applications to pick up changes made in /etc/profile.

    Thanks!

  3. There’s a way to reload a configuration script in the current shell. example:

    . ~/.profile

    This avoids the need to logout and back in again. This is also known as the “source” command, the period being a shorthand for this.

Leave a Reply