I am using iTerm in Mac OS X 10.6. It seems when I open iTerm, neither .bashrc nor .bash_profile is sourced. I can tell because the aliases defined in .bashrc are not set. How to fix?

  • 3
    What's happening is ~/.bash_profile is being invoked by bash first, which is short circuiting the instructions you have in ~/.bashrc. This problem can happen unexpectedly if a rogue program adds some instructions to your ~/.bash_profile when previously the file didn't exist, and you had placed all your bash commands in ~/.bashrc. The solution is to either delete your ~/.bash_profile, or to have ~/.bash_profile source your ~/.bashrc. This can be performed by adding the command: source ~/.bashrc to the end of your ~/.bash_profile and restarting the terminal. – Eric Leschinski Aug 27 '17 at 15:16

13 Answers 13


Bash will source EITHER .bash_profile or .bashrc, depending upon how it is called. If it is a login shell, Bash looks for ~/.bash_profile, ~/.bash_login, or ~/.profile, in that order, and sources the first one it finds (and only that one). If it is not a login shell but is interactive (like most terminal sessions), Bash will source ~/.bashrc.

Likely, iTerm is looking for ~/.bashrc. If it's configured to start as a login shell, it will look for ~/.bash_profile. It's almost certainly an error within the config file rather than that the shell is not sourcing it.

I would put a line at the beginning of each file. At the top of ~/.bash_profile:

export BASH_CONF="bash_profile"

And at the top of ~/.bashrc:

export BASH_CONF="bashrc"

Then, open a new iTerm and type

$ echo $BASH_CONF

That should confirm the file is being sourced and you can look into the syntax of the file.

| improve this answer | |
  • 3
    Setting a different environment variable for each source file allows for more information, that is, if more than one file is sourced, you'll know it, nost just the last one (if not the order sourced.) – kmarsh Nov 23 '15 at 18:47
  • This still doesn't load the .bashrc file. I had to add source ~/.bashrc to my iTerm and Terminal Preferences. btw I'm using Mac OS X 10.9.5. – Giant Elk May 26 '16 at 1:06
  • I just added a .profile file and that automatically works on OS X 10.9.5 without messing in your terminal preferences. – Giant Elk May 26 '16 at 1:11
  • 1
    I found out it is a login shell by going to preferences -> profiles -> general and login shell is selected under command. Valid on MacOS El Capitan and iTerm2 3.0.14 – Aditya Mar 2 '17 at 17:37
  • The solution here did not work for me, but I found a solution. In the beginning, there was no bashrc and no bash_profile. The answer here proposes to create a bashrc. Instead of creating a bashrc file I created a bash_profile, and it worked. Now I need to understand why the bashrc was not executed and the bash_profile yes. – desmond13 Aug 17 '18 at 15:17

In iTerm2, none of these solutions worked for me. I was able to get it to properly read my .bashrc file by adding the command

source ~/.bashrc 

to the Send text at start: field in Settings/General for my iTerm profile.

enter image description here

| improve this answer | |
  • What happened when you did what the accepted answer suggests? No output? – Daniel Beck Jun 13 '12 at 18:15
  • Right. I got no output, and iTerm 2 just loaded the default bash shell with none of my aliases. – Mark Struzinski Jun 13 '12 at 18:25
  • That answer was broken until just now -- the second snippet was supposed to go into ~/.bashrc. Edited it. – Daniel Beck Jun 16 '12 at 6:13
  • I use ZSH and was having the same issue. Except that none of my config file existed in the first place and had to be created. I used this answer and set the "Send text at start" however, when i restarted ZSH created it's .zsh and overwrote my file, i was able to remove the "Send text at start" and add my configs to the newly generated file. Not sure if this helps anyone – Arnolio Dec 8 '16 at 16:23
  • 1
    +1 works like a charm. May add also source ~/.bashrc && source ~/.bash_profile – Carlo Mazzaferro Sep 13 '17 at 19:06

I just wonder do you really use Bash? May be you can use echo $SHELL, it is quite possible that you are using zsh, have you installed on-my-zh?

Acutually I encounter the same problem as you, I fix it by configuring ~/.zshrc instead either ~/.bash_profile for login shell or ~/.bashrc for non-login shell.

Maybe you can have a try

| improve this answer | |
  • 1
    Interesting suggestion, although this question is 3 years old and has an accepted answer. – Tyson Dec 2 '14 at 13:55
  • See this link to also fix the key bindings like Home/Pos1 and End keys. – Daniel W. Dec 2 '19 at 13:11

On my 10.6 machine ~/.profile is sourced. So a source .bashrc entry in ~/.profile should do the job.

| improve this answer | |
  • Worked for me on Mac OS El Capitan. – user674669 Jun 15 '16 at 20:56
  • My experience says you do not want to source one .bashx file from another, they are separate for a reason :) If you are doing that, then something is wrong – Alexander Mills Feb 20 '17 at 21:55
  • @AlexanderMills The reason these files exist is because Mac ripped them straight outta Unix. There's no reason they all shouldn't be loaded for a user. – RaisinBranCrunch Feb 7 '19 at 21:35
  • you can get circular calls if they load each other, is the problem, best way to avoid that is to flip a boolean with an env var and only load the other files if the boolean is not set. – Alexander Mills Feb 7 '19 at 22:03

Easy fix.

1. Open your ~/.zshrc file

2. Add the following line at the end of the file.

source ~/.bash_profile
| improve this answer | |
  • 1
    Brilliant! That did it for me. It never occurred to me that zsh was getting in the way after I installed Oh-my-zh. – Cindy Conway Apr 19 '18 at 14:34

On my 10.9 machine ~/.bash_profile is sourced. So a source .bashrc entry in ~/.bash_profile should do the job.

| improve this answer | |

Put your alias definitions in the bash profile file, you have to create the file but it will be sourced automatically. I create a separate file called alias.configuration and source it in .bash_profile just because I have another user defined and want to have the same alias set.

| improve this answer | |
  • 1
    Actually neither .bashrc nor .bash_profile are sourced. – Computist Aug 7 '11 at 6:02


set -x

to the beginning of /etc/profile. This gives you a line-by-line account of everything that gets executed when bash starts up, including files sourced from within /etc/profile, ~/.bash_profile, etc. It's a bit daunting if you don't understand bash scripting very well, but you may be able to see if there is an error in a start-up file, and the output will be useful for someone proficient in bash to help you locate your problem.

You can remove the set -x line when you're finished troubleshooting.

| improve this answer | |

On 10.10 and iTerm2 2.0, customized profile

  • .bash_rc should work.
  • .bash_profile, try "/bin/bash --login" instead of "/bin/bash"
| improve this answer | |
  • I voted up this answer because it seems to be the only one acknowledging that in OS X,at some point, bash would source ".bash_rc" instead of ".bashrc" . I only came here because I was trying to find out why (and I still don't know). – Marnix A. van Ammers Feb 2 '16 at 18:09

In iTerm2, ensure you're using "login shell" instead of a custom command including "login", which doesn't do what you expect.

| improve this answer | |
  • What does iTerm2 command actually do? – studgeek Apr 9 '16 at 21:24

Make the following change and iTerm will source bashrc

iTerm > Preferences > General > [x] Command: /bin/bash

| improve this answer | |

Problem can be fixed by adding below line into /etc/bashrc

[ -r "$HOME/.bashrc" ] && . "$HOME/.bashrc"

| improve this answer | |

I combined couple solutions together to work it like expected.

.bash_profile source and run on zsh.

Preferences -> Profiles -> General .

Select Command under Command .
And add in the text box /bin/bash --login .

Then in .bash_profile add line /bin/zsh --login

That's it.

| improve this answer | |
  • (1) What? (2) If you are having bash always run zsh, that is not what anybody expects. – Scott Mar 5 '18 at 5:56
  • If I set /bin/bash --login, it doesn't provide any features of zsh. Then If I change it to loginshell in preference, it doesn't read .bash_profile. Everytime I have to run source ~/.bash_profile manually. @Scott After doing the above things, I have zsh in the required way. – muhammed basil Mar 5 '18 at 8:07
  • (1) My point is that zsh might be what you desire, but it is not required or asked for by this question, which is tagged [bash] and doesn’t say anything about zsh.  (2) If you define aliases and shell functions and set variables (without exporting them) in your .bashrc and/or .bash_profile, are they available to you in your zsh shell? – Scott Mar 5 '18 at 15:32

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.