65
18
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?
65
18
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?
53
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.
3Setting 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 – 2015-11-23T18:47:02.463
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 – 2016-05-26T01:06:12.840
I just added a .profile file and that automatically works on OS X 10.9.5 without messing in your terminal preferences. – Giant Elk – 2016-05-26T01:11:41.993
1I 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 – 2017-03-02T17:37:40.767
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. – kalmanIsAGameChanger – 2018-08-17T15:17:30.013
This solution is outdated, check the next post with more kudos :) – Macilias – 2019-02-26T10:09:35.623
70
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.
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 – 2016-12-08T16:23:59.343
I thought this was my problem.. and then along the way realized that my home catalogue was not the folder I started out in.. so as I moved my .bash_profile to another location and I thought I was ln -s (symlinking to it from my ~ (home) catalogue, I was in fact adding a symlink in the wrong folder. Adding this here in case it helps someone else, who was going for this answer. – Alisso – 2017-04-17T12:45:35.400
1+1 works like a charm. May add also source ~/.bashrc && source ~/.bash_profile
– Carlo Mazzaferro – 2017-09-13T19:06:52.363
For MAC OS Mojave: Preferences->Profile->General. I was looking for above option in the Preferences->General instead. This works smooth. Thanks! – jok – 2019-04-05T23:40:24.080
What happened when you did what the accepted answer suggests? No output? – Daniel Beck – 2012-06-13T18:15:56.407
Right. I got no output, and iTerm 2 just loaded the default bash shell with none of my aliases. – Mark Struzinski – 2012-06-13T18:25:23.297
That answer was broken until just now -- the second snippet was supposed to go into ~/.bashrc
. Edited it. – Daniel Beck – 2012-06-16T06:13:33.157
24
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
1Interesting suggestion, although this question is 3 years old and has an accepted answer. – Tyson – 2014-12-02T13:55:17.557
See this link to also fix the key bindings like Home/Pos1 and End keys.
– Daniel W. – 2019-12-02T13:11:09.83312
On my 10.6 machine ~/.profile
is sourced. So a source .bashrc
entry in ~/.profile
should do the job.
Worked for me on Mac OS El Capitan. – user674669 – 2016-06-15T20:56:10.717
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 – 2017-02-20T21:55:01.857
@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 – 2019-02-07T21:35:27.170
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 – 2019-02-07T22:03:49.173
8
Easy fix.
1. Open your ~/.zshrc
file
2. Add the following line at the end of the file.
source ~/.bash_profile
1Brilliant! 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 – 2018-04-19T14:34:00.953
6
On my 10.9 machine ~/.bash_profile is sourced. So a source .bashrc entry in ~/.bash_profile should do the job.
1
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.
1Actually neither .bashrc
nor .bash_profile
are sourced. – Computist – 2011-08-07T06:02:54.717
1
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.
1
On 10.10 and iTerm2 2.0, customized profile
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 – 2016-02-02T18:09:08.807
0
Make the following change and iTerm will source bashrc
iTerm > Preferences > General > [x] Command: /bin/bash
0
Problem can be fixed by adding below line into /etc/bashrc
[ -r "$HOME/.bashrc" ] && . "$HOME/.bashrc"
0
In iTerm2, ensure you're using "login shell" instead of a custom command including "login", which doesn't do what you expect.
What does iTerm2 command actually do? – studgeek – 2016-04-09T21:24:07.757
-1
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.
(1) What? (2) If you are having bash
always run zsh
, that is not what anybody expects. – Scott – 2018-03-05T05:56:50.197
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 – 2018-03-05T08:07:03.657
(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 – 2018-03-05T15:32:10.557
3What'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 – 2017-08-27T15:16:55.473