How to use the "right" version of Git in your Mac
So you have just downloaded the latest version of git, installed on your mac , but when you went to Terminal and typed git --version you saw an unexpected version of Git ???
The problem could be that, some of your previous installations (probably Apple Dev Tools), had installed the version that you are seeing now. Don't worry, let's fix that now and then I will do my best to explain why.
Go to your terminal and access your etc directory :
cd ../../etc
Ok, in this directory open the paths file with your preferred text editor:
Eg: mate paths
Add this line to the top of your file:
/usr/local/git/bin
When you are done, it should look like something like this
/usr/local/git/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
(note: the file will show one path per line)
Close your Terminal and open it again, now try:
git --version
Well, what we just did ?
Right, the default directory where Git was installed : /usr/local/git/bin.
Once installed we have to add this path in the PATH variable usually using the command:
export PATH=$PATH:/usr/local/git/bin
So the bash can resolve what we are calling when git is typed.
So far so good, the problem is that this command adds the git home to the end of the PATH variable, and our previous installation has put Git in other directory than the default: /usr/bin. This directory comes before (in the PATH variable) the default path of our new git installation. So what happens when we type git --version ? The "wrong" path is resolved to our command, because /usr/bin was loaded before that /usr/local/git/bin and we get the unwanted installation of Git.
So, one way to solve this problem, is make sure that the wanted path will be loaded first, and we did this by editing the paths file, responsible to compose the PATH variable.
This was how I solved that problem I hope that this can help you too.
I really would like to hear about your own experience or better ways to solve it !!
Written by Everton Maldonado
Related protips
1 Response
You can use a package manager like Homebrew to install the packages you need (ex. brew install git
). As long as /usr/local/bin
is before /usr/bin
in $PATH
, brew
installed binaries will have the priority.