18

I installed Git on my Mac but I do not know how to run it or access it. From the terminal I type git but it says "command is invalid."

I downloaded git from http://code.google.com/p/git-osx-installer/downloads/list?can=3 and I downloaded the package "Git Installer 1.7.3.5 - OS X - Leopard - x86_64."

UPDATE 1:

The content of the package is the following:

  • README.txt
  • git-1.7.3.5-x86_64-leopard.pkg
  • setup git PATH for non-terminal programs.sh
  • uninstall.sh

When I execute "setup git PATH for non-terminal programs.sh," I get the following messages:

No change to PATH in ~/.MacOSX/environment.plist
~ /Volumes/Git 1.7.3.5 x86_64 Leopard /Volumes/Git 1.7.3.5 x86_64 Leopard -MacBook-Pro:Git 1.7.3.5 x86_64 Leopard$ $PATH -bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory

UPDATE 2:

The content of my profile file is the following one:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
fi
apaderno
  • 28,547
  • 16
  • 75
  • 90
johndoe
  • 207
  • 1
  • 3
  • 7
  • Where did you get the installer from? It is probably a question of ensuring the right directory is on your PATH, or that you're using the right command. I have a Mac, but I build git from source, so I know where I put it. That doesn't help you (beyond letting you know it is pretty easy to do). – Jonathan Leffler Jan 18 '11 at 14:56
  • 3
    Have you restarted your terminal? Not sure the PATH variable gets updated right away. – Eiko Jan 18 '11 at 14:58
  • updated the question with little more information! – johndoe Jan 18 '11 at 15:01
  • Where exactly is your `git` executable? – miku Jan 18 '11 at 15:05
  • I have this DMG file => git-1.7.3.5-x86_64-leopard.dmg – johndoe Jan 18 '11 at 15:06
  • 3
    At any point during the installation process, did you see a screen like this: http://progit.org/figures/ch1/18333fig0107-tn.png ? If not, then you downloaded git without installing it... – las3rjock Jan 18 '11 at 15:16
  • Presumably you did actually run the installer, so /usr/local/git/bin exists with git in it? Which shell do you use? As far as I know, the default is `tcsh`, but it does not use `.profile` (it uses `.login`), so that could account for the path not being set. – Jonathan Leffler Jan 18 '11 at 15:18

7 Answers7

22

The git-osx-installer that you used should have installed git into /usr/local/git. See if you can cd into that directory. If you can, then check that your PATH was correctly set by running echo $PATH from the terminal and making sure that you see /usr/local/git/bin in the included PATH. If not, you need to add it to your PATH.

Did you run the included shell script setup git PATH for non-terminal programs.sh?

Update 1: How to run the included shell script

  1. Mount the git-osx-installer disk image by double-clicking git-1.7.3.5-x86_64-leopard.dmg, which should be located in your Downloads folder.
  2. Open Terminal from /Applications/Utilities/Terminal
  3. Type cd /Volumes/Git 1.7.3.5 x86_64 Leopard/
  4. Type ./setup git PATH for non-terminal programs.sh and hit Enter to run the shell script. Note: Once you type ./setup you can hit the Tab key and it will autocomplete for you.
  5. Open a new Terminal and type echo $PATH
  6. Confirm that you see /usr/local/git/bin in your PATH.

Update 2: Show Git Who's the Master

Open Terminal and issue the following commands:

echo "/usr/local/git/bin" > git
sudo mv git /etc/paths.d

When you run sudo it will ask for your OS X password.

After issuing those two commands, you should be able to open a new Terminal window and see /usr/local/git/bin when you run echo $PATH.

For this to work you have to have the following in /etc/profile, which it does by default:

if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
fi
Matthew Rankin
  • 457,139
  • 39
  • 126
  • 163
  • I run and got the following: > cd /usr/local/git -bash: cd: cd: No such file or directory – johndoe Jan 18 '11 at 15:13
  • 1
    @johndoe: you have to install the package as well as download it. – Jonathan Leffler Jan 18 '11 at 15:21
  • I just installed the package again now what should I do? – johndoe Jan 18 '11 at 15:21
  • I can see the git folder in usr/local/git/bin now how should I run the git command. – johndoe Jan 18 '11 at 15:23
  • @johndoe: Did you run the included shell script `setup git PATH for non-terminal programs.sh`? If not, I'd run that. Also, when you run `echo $PATH` from the terminal does it include `/usr/local/git/bin`? – Matthew Rankin Jan 18 '11 at 15:26
  • how do I run the script? when i click on it it opens in a text editor. – johndoe Jan 18 '11 at 15:29
  • I just dragged the script on the terminal. not sure if it ran or not. But I do not see the path when I echo. echo $PATH /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec – johndoe Jan 18 '11 at 15:31
  • Open a Terminal window and try running `git` . If that doesn't seem to work, then run `cd /usr/local/git/bin`, then try running `./git` – las3rjock Jan 18 '11 at 15:32
  • ./git seems to be working but I want to access git from everywhere! not only from the git\bin directory. – johndoe Jan 18 '11 at 15:35
  • Try this. From a Terminal window, run `cd "/Volumes/Git 1.7.3.5 x86_64 Leopard"` . Then run `/bin/sh "setup git PATH for non-terminal programs.sh"` . Then run `echo $PATH` and check if `/usr/local/git/bin` has been added somewhere to your PATH. – las3rjock Jan 18 '11 at 15:45
  • @las3rjock ran the command in UPDATE 2 (original post) the path was not added. – johndoe Jan 18 '11 at 15:53
  • It seems that changes to `~/.MacOSX/environment.plist` do not take immediate effect, so you may need to log out of your account and log back in to see the change in your PATH. Alternatively, you could just restart your Mac (which has the same effect as logging out and logging back in). – las3rjock Jan 18 '11 at 16:02
  • @johndoe: Well, bugger. As @las3rjock recommended, what happens when you log out and log back in to OS X? – Matthew Rankin Jan 18 '11 at 16:05
  • I just restarted the machine and same thing! I do not see git in the $PATH value. – johndoe Jan 18 '11 at 16:12
  • @johndoe: Try the commands that I list in Update 2 of my answer. That will add `/usr/local/git/bin` to your `PATH`. – Matthew Rankin Jan 18 '11 at 16:27
  • I closed the terminal after the update 2 and ran it again and got the following: -MacBook-Pro:~ johndoe$ $PATH -bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory – johndoe Jan 18 '11 at 16:42
  • Make sure that your `/etc/profile` has the commands that I list at the bottom of Update 2. Also, make sure that the file `/etc/paths.d/git` contains the single line `/usr/local/git/bin` – Matthew Rankin Jan 18 '11 at 16:48
  • The git file inside the paths.d contains the line that you have pointed out. The profile file contains the implementation which is shown in update 3 (original question) – johndoe Jan 18 '11 at 16:54
  • At this point, the following Super User entry may be helpful: http://superuser.com/questions/69130/where-does-path-get-set-in-os-x-10-6-snow-leopard – las3rjock Jan 18 '11 at 18:51
  • Is there any git installation for mac like on windows msysgit which just works without all this trouble! – johndoe Jan 18 '11 at 19:17
  • Working through this question has actually been very illuminating for me, because I installed git on my new MacBook Pro a few months ago without any problems, but in the process of trying to get git working on your machine, I've come to realize that I have no idea why it's working on my machine! See http://en.wikipedia.org/wiki/Unusual_software_bug#Schr.C3.B6dinbug – las3rjock Jan 18 '11 at 19:37
  • The problems is the paths are being updated! Is there anyway I can manually go and update the PATHS so I can run git from anywhere! – johndoe Jan 18 '11 at 19:54
  • This is what I get when I run $PATH -bash: /usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec: No such file or directory – johndoe Jan 18 '11 at 19:55
  • I got it! I went to this site and ran the script and it installed git on my machine. Now everything works => http://www.freshblurbs.com/installing-git-os-x-3-minutes – johndoe Jan 18 '11 at 20:08
  • @johndoe: I suppose when all else fails, you can always build `git` from source! Congratulations on now having a working `git` install! – las3rjock Jan 18 '11 at 20:14
5

A general introduction:

Git Immersion is a guided tour that walks through the fundamentals of Git, inspired by the premise that to know a thing is to do it.

miku
  • 181,842
  • 47
  • 306
  • 310
1

Either '/usr/local/bin' is not in your PATH or it just does not find git ...

Try this

$ PATH='/usr/local/bin'
$ export PATH

RESTART CONSOLE

try again - if it still does not work

  1. check if the location /opt/local/bin/git or /opt/local/bin/github exists (depending on your version)

if so:

2 . type

$ sudo ln -s /opt/local/bin/git /usr/bin/git

or

$ sudo ln -s /opt/local/bin/git /usr/bin/github (depends on your version)

3 . should work now

1

It may be easier to create a symbolic link from one of your default paths:

sudo ln -s /usr/local/git/bin/git /usr/local/bin/git
vol7ron
  • 40,809
  • 21
  • 119
  • 172
1

Use MacPorts:

sudo port install git
baton
  • 297
  • 1
  • 3
  • 1
    Well yes, that requires [macports](http://www.macports.org/install.php) first. An alternative is [homebrew](http://mxcl.github.com/homebrew/). But as you will see, those will guide you through similar PATH setup as needed with the git package you installed. You'll have better value learning some basics on using the unix shell anyway. – Damien Pollet Jan 18 '11 at 15:05
  • @johndoe: That means that you don't have MacPorts installed. Personally, I don't use MacPorts, and it's not needed to solve your problem. I have git installed without problems using the same git-osx-installer that you used. – Matthew Rankin Jan 18 '11 at 15:07
0

Why not just run it directly? You can learn to configure it when you become more experienced.

Check if you can run git to see the current version installed

/usr/local/git/bin/git --version

Check if you can run git to see the help available

/usr/local/git/bin/git --help

Later, after you learn how to use git, you can configure your path to automatically find git, by changing your path, using shell scripts, symbolic links. Any of these will then allow you to run:

git --version

git --help

When working with java or mvn or eclipse, the same goes. Try running the simplest command first to make sure you can actually run. Then, figure out how to simplify the process. If git was installed in another directory, search for it, then run it using the entire path.

Scott Izu
  • 2,229
  • 25
  • 12
-2

I think I know what you mean. I did the following to start using:

Open your terminal and run the following command

cd /usr/local/git/bin

than try to run, for example:

git --version

or

git --help
svvac
  • 5,814
  • 3
  • 17
  • 22
  • It's a bit inconvenient if you have to cd to the installation directory every time you want to use git. – JJJ Jun 11 '14 at 11:18