I have an issue where, when I load up new terminal windows, I have to source the ~/.profile to get my PHP path working correctly.

In essence of my issue is getting terminal to use MAMP PHP and MySQL instead of default.

I have the paths mapped out, but everytime I open a new window, I have to use the command

source ~/.profile

Is there a reason Mac OS X wouldn’t be registering/sourcing/[insert correct term here] the .profile? I’ve read .bash_profile will override .profile, but the PHP path is defined in .bash_profile as well.

Here are the contents of each file.

The contents of .bash_profile:

export PATH="$PATH:/Users/[username]/bin:/Applications/MAMP/bin/php/php5.5.14/bin:/Applications/MAMP/bin/mysql"

The contents of .profile:

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.14/bin
  • 1
    The OS X Terminal opens a login shell by default, so it should source .bash_profile. Are you sure .bash_profile is sourced? Put an echo "sourcing bash profile" statement in it and try. And indeed, when .bash_profile exists, .profile will not be sourced (see Bash manual) – slhck Mar 19 '15 at 15:04
  • @slhck - is the way the path includes in my bash_profile not correct? They way I'm reading it, I can give multiple path options in the extport PATH= line, or set t0 variables/params/whatever with export FOO=BAR and then include paths in succession via : separated values in the PATH declaration. If bash is overriding profile, then is the PATH declaration in my bash busted? – Tim Plummer Mar 19 '15 at 17:20
  • @slhck - so, that might have been it. I changed the order of the declaration in the bash_profile to export PATH=/foo/bar:/Applications/whatever:$PATH and it seems to be working. So $PATH has to go at the end. I didn't think that mattered, but if I had a nickel for every time I was wrong... – Tim Plummer Mar 19 '15 at 17:24
  • 1
    Are you 100% sure this is not working? What is the output of which mysql and which php? How about echo $PATH as well? – JakeGould Mar 19 '15 at 18:01
  • No, your PATH can go at the beginning as well, it just changes the order of preference. Perhaps there was another issue, but either way you may want to post an answer explaining how you solved it. – slhck Mar 19 '15 at 19:53

I believe the answer is clear when you look at the logical order of what you have set in .bash_profile (which doesn’t work) when compared to .profile (which does work).

Here is your .bash_profile:

export PATH="$PATH:/Users/[username]/bin:/Applications/MAMP/bin/php/php5.5.14/bin:/Applications/MAMP/bin/mysql"

And here is your .profile:

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.14/bin

The key to solving this is to look at where you are setting your new MAMP related items when compared to the default $PATH; order counts because the shell will act on (key thing) the first item it finds in its list of user search paths.

Knowing that you can breakdown the behavior you are seeing like this:

  • In the .profile version you are setting $MAMP_PHP as a variable and then prepending it to the beginning of the $PATH.
  • But in .bash_profile version you are appending this stuff after $PATH: :/Applications/MAMP/bin/php/php5.5.14/bin:/Applications/MAMP/bin/mysql

So I would rework .bash_profile like this to make it work:

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.14/bin
export PATH="$MAMP_PHP:$PATH:/Users/[username]/bin"

Note how I am using the $MAMP_PHP convention from .profile—which is a nice way of logically separating paths for human eyes—and how I simply set that value to /Applications/MAMP/bin/php/php5.5.14/bin since I have no idea when this MySQL path would be used: /Applications/MAMP/bin/mysql.

From my vantage point using MAMP version 2.1.3 I don’t see an actual mysql binary in the path you have set. Traditionally this would be in the /Applications/MAMP/Library/bin/ directory along with other MAMP core binaries. So maybe your .bash_profile should be adjusted like this:

export MAMP_BIN=/Applications/MAMP/Library/bin
export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.14/bin
export PATH="$MAMP_BIN:$MAMP_PHP:$PATH:/Users/[username]/bin"

Also, that /Users/[username]/bin seems kludgy and too specific for me. If you are maintaining a user directory specific ~/bin directory you might want to just set it to ~/bin like this:

export MAMP_BIN=/Applications/MAMP/Library/bin
export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.14/bin
export PATH="$MAMP_BIN:$MAMP_PHP:$PATH":~/bin

Note how there are no double quotes (") around the last :~/bin part; that allows ~/ to properly expand to your user’s home directory. That way you could cleanly use a .bash_profile setup like this on any user account where the user has ~/bin directory.


Bash looks in your home directory for .bash_profile, .bash_login, and .profile in that order. Then bash will run the first of these that it finds and stop looking.

So, a solution for you, can be to source your .profile at the end of your .bash_profile, or simpler, copy both lines on your .profile at the end of your .bash_profile.

  • 1
    The OP said they had the respective lines in .bash_profile anyway. So it's apparently not sourced. – slhck Mar 19 '15 at 15:41

In Unix FAQ (for OS X) we can read:

Bash Startup Files

When a "login shell" starts up, it reads the file "/etc/profile" and then "~/.bash_profile" or "~/.bash_login" or "~/.profile" (whichever one exists - it only reads ONE of these, checking for them in the order mentioned).

When a "non-login shell" starts up, it reads the file "/etc/bashrc" and then the file "~/.bashrc".

Note that when bash is invoked with the name "sh", it tries to mimic the startup sequence of the Bourne shell ("sh"). In particular, a non-login shell invoked as "sh" does not read any dot files by default. See the bash man page for details.

So if you've already ~/.bash_profile, the file ~/.profile won't be automatically read by bash, so you can add the following lines in your ~/.bash_profile to load it:

# Load user profile file
if [ -f ~/.profile ]; then
  . ~/.profile
  • 1
    “So if you've already ~/.bash_profile, the file ~/.profile won't be automatically read by bash…” Yes, that is true. But not the core issue. The core issue is why the MAMP paths are no paid attention to when they are in the ~/.bash_profile but they do work when they are in the ~/.profile which is force-loaded by source ~/.profile. – JakeGould Mar 19 '15 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.