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:

  1. ~/.bash_profile
  2. ~/.bash_login
  3. ~/.profile

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!


About johnnywey

Welcome to A Regular Expression. This blog is designed to reflect my thoughts on life, music, software design, Apple, faith, philosophy, and whatever else I can think of.

Posted on April 17, 2008, in Apple, Programming. Bookmark the permalink. 31 Comments.

  1. Anonymous Coward

    I totally just did the same thing yesterday (installed a .bash_profile) and everything stopped working today. Thanks for the fix!

  2. Thanks Johnny, this was exactly my problem too.

  3. Sweet, thanks for the tip. I had installed MacPorts but couldn’t figure out why it wasn’t in my path. This fixed it.

  4. Thank you for posting this. My problem too.

  5. Thank you so much for posting this. I just spent hours try to figure out ..

  6. THANKS! That saved my day. Now sdl-config is found in terminal :)

  7. Thanks for taking the time to write this up Johnny, was exactly my problem!

    (not sure who created .bash_login, although I did see Postgres in the PATH there)

  8. Installed Lift Web Framework. Sure enough the installer made a bash_profile file.


  9. You can edit .bash_profile and type at the end: source ~/.profile or any file name, it will work :)

  10. Thanks for the explanation!

    Out of curiosity, what do you find is the best place/way to learn about bash and shell scripting in general.

  11. Thank you thank you thank you. This has been bugging me for a while!

  12. Thank you! This has been bothering me for a while, having to do $source ~/.profile to load my custom PATH variables. It turns out MacPorts had messed with my .bash_profile file without me realizing it. Thanks again!

  13. Thank you so much for posting this. This was bugging me today.

  14. You, sir, are awesome.

  15. Thanks. I’m trying to get up to speed with python/mysql on OS X. Taking a detour through ‘Learning Unix for Mac OS X’, I tripped over this problem. The book said to build a .profile but it didn’t work. Now I know why. Thank you,

  16. What’s the actual fix?

    • Exactly! What is the fix? I see the issue is pointed out…but I don’t see what you did to fix the incorrect pointers, etc? I know this is 4 years later, but still an issue on el Capitan after install MacPorts and Wine.

  17. For future google searchers… I had the same problem after installing rvm for ruby, it adds a .bash_profile during install.

  18. Cheers fella, always worth writing these things up no matter how simple. That just helped me solve a problem I was having nice and quickly before I started tearing my hair out. Thanks again.

  19. Yours is only the second site that I have found with this information and the first one was not confident… I have been playing with this and am quite happy to find this information- very helpful…. but whatever happened to .bashrc from the old unix days! CONFUSING.

  20. Perfect, thanks!

  21. Thank you for posting this. I was wondering why .profile was being respected, and it turns out that the RVM installer I ran a while back had created its own .bash_profile file.

  22. Gosh thank you so much! No wonder a lot of my terminal commands weren’t working!

  23. Thanks, exactly the problem I had!

  24. Thanks for nice explanation! it really helps me a lot. You are marvellous!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: