Array
University of Oregon

MacOS: XCode Not Needed

After installing Git, run this command in the terminal:

git --version

If you are prompted to install XCode Tools, see your instructors during Help Hours, or follow these instructions to fix the problem on your own.

It is not necessary to install XCode. The solution is to update your OS X  execution path.

Adding the directory to the path will prevent Mac OS X from asking you to install XCode each time you type git in the terminal.


The Cause of the Problem

Your Mac expects expects Git to be installed in /usr/bin/git, which is where XCode installs it.

Git’s official installer puts Git in /usr/local/git/bin/.

To stop OS X from prompting you to add XCode, you need to edit a file named .bash_profile file in your home directory and set the PATH there.

.bash_profile controls various shell environment preferences including PATH.

You can resolve this conflict by placing /usr/local/git/bin before /usr/bin in the execution PATH. 

There are two ways to do this– pick one of the following:


Fix the Problem, Using the Shell:

Open the terminal app, and run these two commands:

echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile
source ~/.bash_profile


Or, Fix the Problem, Using Nano:

 

nano-editor-800px

Launch Nano

Nano is a command-line text editor built-in to Unix.

  1. Enter the cd command without any arguments, to move to your home directory.
  2. Enter the pwd command to verify that you are in your home directory.
  3. Enter the nano .bash_profile command.

    This will open the file in Nano.

    Nano commands are invoked by holding down the Ctrl key (that is, the control key), and pressing another key.

    The control key is referred to using ^. For example, ^X means “hold down the Control key and press the x key”.

    Most of the important commands are listed at the bottom of the Nano screen.

  4. Add the following line to .bash_profile:

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

  5. Save the changes in Nano: control-O.
  6. Exit Nano: control-X
  7. Notify the shell of your changes to PATH.

    Unix dot-files are read by the shell when you first start the terminal, or login to a remote computer.

    If you change .bash_profile, run this source command to have the changes take effect:

    source ~/.bash_profile

  8. Now you should be able to run Git without XCode:

    which git
    git --version


Optional Readings

The Unix PATH Variable

PATH is an environment variable on Unix systems (OS X) and Windows, specifying a set of directories where executable programs are located.

For example, when you run any git command such as the following:

git --version

The shell uses the PATH variable to find where Git is installed on your computer, and then runs it.

Problems emerge when you have Git installed in a different place than what is in the PATH.


Other Unix Commands

which — locate a program file in the user’s path.

command -v git — same.

whereis — locate programs. whereis checks the standard directories for the specified program, printing out the paths of any it finds.

echo $PATH — display the value of the PATH variable.

Let’s use these commands as follows:

  1. echo $PATH

    This command shows what is in the PATH.

    Example: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

    Example: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

  2. which git

    This command shows us just that part of the PATH relevant to Git.

    Example: /usr/bin/git

    Example: /usr/local/git/bin/git

  3. whereis git

    This command shows where Git is installed on your computer. Note: it could be installed in more than one place, depending on your history of installing Git.

    Example: /usr/bin/git

    Example: /usr/local/git/bin/git

Skip to toolbar