Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I realize there are /etc/profile and /etc/bashrc files for setting global environment variables and maybe I'm just misunderstanding their purposes, but...

Is there a global bash_profile file?

I'm using Mac OS X

share|improve this question
up vote 7 down vote accepted

It's not called bash_profile, but the standard place for global bash configuration is /etc/bash.bashrc. It's usual to call this from /etc/profile if the shell is bash. For example, in my /etc/profile I have:

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1=’0
    if [ ‐f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc

In terms of usage, /etc/profile provides system-wide configuration for all Bourne compatible shells (sh, bash, ksh, etc.). There's normally no need for an equivalent /etc/bash_profile, because the intention of the profile file is to control behaviour for login shells. Normally anything you want to do there is not going to be bash-specific. /etc/bash.bashrc is bash-specific, and will be run for both login and non-login shells.

To further complicate things, it looks like OS X doesn't even have an /etc/bash.bashrc. This is probably related to the fact that Terminals in OS X default to running as login shells, so the distinction is lost:

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

I don't run OS X, so the extent of my knowledge ends there.

share|improve this answer
Don't read /etc/bash.bashrc from a non-interactive shell. /etc/profile can be read by non-interactive shell. See Difference between Login Shell and Non-Login Shell? – Gilles Sep 23 '12 at 2:18
@Gilles - I'm not clear what point you're trying to make here. A non-interactive login shell is an unusual thing indeed. For reference, the code I quote isn't my own creation. It's from the default /etc/profile in Ubuntu 12.04. What would you suggest instead if one wanted an /etc/profile which was executed only under bash, and no other sh-compatible shell? – ire_and_curses Sep 23 '12 at 2:27
The system /etc/profile file for my system contains a comment at the top that reads: # System-wide .profile for sh(1). Does this mean profile is sh specific? Does sh somehow run before bash? – user23312 Sep 23 '12 at 2:40
@Josh Voigts - sh is a subset of bash. /etc/profile is executed for sh, bash, and all other Bourne-compatible shells. – ire_and_curses Sep 24 '12 at 5:31
@ire_and_curses It appears the file is called /etc/bashrc on the mac, not /etc/bash.bashrc. It also appears to run for /bin/sh as well. – BrainStorm.exe Aug 11 '15 at 23:48

/etc/profile is the global bash_profile. There's no file that's specific to bash, bash just reads the standard file read by all Bourne-style shell. That's where you can set system-wide environment variables.

See Alternative to .bashrc for a generic overview of bash's common startup files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.