Super User is a question and answer site for computer enthusiasts and power users. 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 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 don't work. How to fix?

share|improve this question

migrated from stackoverflow.com Aug 7 '11 at 9:57

This question came from our site for professional and enthusiast programmers.

10 Answers 10

up vote 26 down vote accepted

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.

share|improve this answer
    
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 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 at 1:11

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

share|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

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

share|improve this answer
    
Worked for me on Mac OS El Capitan. – user674669 Jun 15 at 20:56

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

share|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

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

share|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.

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

On 10.10 and iTerm2 2.0, customized profile

  • .bash_rc should work.
  • .bash_profile, try "/bin/bash --login" instead of "/bin/bash"
share|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 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.

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

Add

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.

share|improve this answer

Make the following change and iTerm will source bashrc

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .