How to fix Terminal not loading ~/.bashrc on OS X Lion

Jakub Arnold picture Jakub Arnold · Oct 15, 2011 · Viewed 102.6k times · Source

Whenever I open a new tab in Terminal using Cmd + T, it opens bash in the same directory, as the previous tab. This works fine when I'm in the ~ directory, but if I'm anywhere else, I get an error loading .bashrc

Last login: Sat Oct 15 21:10:00 on ttys002
-bash: .bashrc: No such file or directory
Jakub-Arnolds-MacBook-Pro:projects darth$ 

It looks like .bashrc is loaded via relative and not absolute path, because if I do source ~/.bashrc, everything works smoothly.

loaded bashrc

I think this is a OS X Lion related problem, because before the upgrade from Snow Leopard, I didn't have the same issue. But that might be caused by Terminal always opening at ~, I don't remember if it tried to open the same directory.

However the question remains the same, how can I make Terminal load ~/.bashrc via absolute path, and not relative?

Answer

ckruse picture ckruse · Oct 15, 2011

Terminal opens a login shell. This means, ~/.bash_profile will get executed, ~/.bashrc not.

The solution on most systems is to "require" the ~/.bashrc in the ~/.bash_profile: just put this snippet in your ~/.bash_profile:

[[ -s ~/.bashrc ]] && source ~/.bashrc