2

On my new 2014 Mac (OS X 10.9 Mavericks), I have just installed Git using Homebrew. In order to install Homebrew, I had to download and install XCode 5. So now, when I enter the command which git, I can see that Git is running from a different file pathway than the rest of the Homebrew installation. Git's different pathway is /usr/bin/git. I believe it is supposed to be in /usr/local/bin/ instead, with the rest of Homebrew.

I found a solution to getting Git to run from the Homebrew installation (and consequently an updated version of Git). According to another Q&A on this site, the solution is to add export PATH="/usr/local/bin:$PATH" in ~/.bash_profile.

Unfortunately, I don't understand where to enter that information. When I'm in Terminal, I can't change directories to something called "~/.bash_profile." How do I get there to enter the command export PATH="/usr/local/bin:$PATH"? I tried entering the command /usr/bin/open ~/.bash_profile, but Terminal tells me: The file /Users/**MYNAME**/.bash_profile does not exist.

3
  • Let's trouble shoot this in a chat room: chat.stackexchange.com/rooms/17163/…
    – Ian C.
    Commented Sep 15, 2014 at 2:42
  • I would love to, thank you for offering! But I don't have enough reputation points to participate in a chat room yet. Is there another forum we can use?
    – joker6
    Commented Sep 16, 2014 at 4:17
  • You should have access to that chat now.
    – Ian C.
    Commented Sep 16, 2014 at 6:30

1 Answer 1

2

This: ~/.bash_profile is a file, not a directory. It's a file that gets executed when you start a bash login shell:

A login shell is a bash shell that is started with - or --login.

When BASH is invoked as a login shell, the following files are executed in the displayed order.

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

To ensure your Homebrew-installed tools appear before any other tools you can copy and paste the following in to a terminal window to update your ~/.bash_profile file:

cat << 'EOF' >> ~/.bash_profile

export PATH="/usr/local/bin:$PATH"
EOF

This will append (>>) the necessary lines to ~/.bash_profile for you in a safe manner. The append will create the file if it does not exist. The heredoc syntax used above is explained in this nice StackOverflow answer.

After making changes to your .bash_profile file you need to reload it or start a new Terminal session to see the change. To reload it in your existing session type:

source ~/.bash_profile
5
  • Thank you. My limited knowledge of Terminal: Running Git and Haml/Sass commands! So, on a new line in a new window, I copied/pasted your recommended command. This had no effect; when I checked on the location of my git repository again by typing which git, the pathway was in the same incorrect location. I was asked to run sudo commands to update XCode, so I did, and then was asked to run brew doctor again. I watched a new empty git repo initialize within /usr/local/.git/. But when I type which git again on a new line to verify that correct location, I just see /usr/bin/git again.
    – joker6
    Commented Sep 15, 2014 at 1:05
  • After changing your .bash_profile file you need to start a new Terminal to load the changes or run source ~/.bash_profile in your existing Terminal.
    – Ian C.
    Commented Sep 15, 2014 at 1:10
  • I have quit Terminal, re-opened it, and run your original cat command again. Then I entered your additional command, source ~/.bash_profile on a new line. I typed in which git again, but am still seeing the incorrect file pathway.
    – joker6
    Commented Sep 15, 2014 at 1:27
  • I've reviewed the answer from the question I referenced originally. Someone advised opening .bash_profile in a text editor with the command /usr/bin/open ~/.bash_profile. I entered this command and found my export PATH="/usr/local/bin:$PATH" command written several times (for each time I've duplicated the Terminal command). I erased the duplicate entries and kept one line of that export PATH(etc.) command. Does this mean that I'm now ACTUALLY using Git from Homebrew's installation in /usr/local/.git/--even if the which git command always shows me /usr/bin/git instead?
    – joker6
    Commented Sep 15, 2014 at 1:49
  • If which git is showing you /usr/bin/git and not /usr/local/bin/git then you're not using the Homebrew version of git.
    – Ian C.
    Commented Sep 15, 2014 at 2:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .