Fixing Bash .profile in OS X
I had a really weird problem that was bugging me for a few months. Like a lot of developers, I use the terminal in OS X a lot. In fact, I’d say I use it far more than Finder for many tasks. However, a while back I noticed that I could not get changes to my .profile to register with the environment. So, if I added something like
it would not update the $PATH environment variable. I spent a bit of time trying to troubleshoot this before, but ended by giving up and simply modifying the “master” profile file in /etc. This, of course, is not the best idea because all Bash users are affected by this file. However, since I am the only user on my machine that cares about such things it wasn’t too big a deal.
Things changed today. I finally got really irritated with the whole thing and discovered what was going on. Bash tries to find local profile files in the following order:
You’ll notice that ~/.profile is the last file in the list. The caveat here is that if Bash finds a file, it processes it and subsequently skips looking for the next file(s) in the list. So, if ~/.bash_profile exists, ~/.bash_login and ~/.profile won’t be processed. Sure enough, I had (or some installer had) placed a ~/.bash_profile file in my home directory a little under a year ago and, because of that, my .profile was not being executed. Doh!