ayjay
ayjay

Reputation: 1382

Do I have 2 kinds of git installed in my Mac? If so, which one will be used by default?

If I type on the terminal:

> git --version
git version 2.21.1 (Apple Git-122.3)

And if I type:

> brew upgrade git
Warning: git 2.25.0_1 already installed

I'm guessing, my computer has 2 kinds of git installed? If so, which one will be used by default in this case?

Also, what do you suggest I do in this case moving forward? Which one do you suggest I remove and why?


EDIT:

Also, if I type:

> git --version
git version 2.21.1 (Apple Git-122.3)

> echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Users/aj/.rvm/bin

Why is the echoed path looks weird?

Upvotes: 15

Views: 9242

Answers (3)

Meysam
Meysam

Reputation: 18117

The git installed by brew can be found under /usr/local/Cellar/git/{version}/bin/git

The git shipped by mac is under /usr/bin/git.

If you run which git, you can see which one is being used. If /usr/bin/git is in use and you want the one installed by brew, you can run the following command:

brew link git

It creates a symbolic link under /usr/local/bin that will point to the git found under Cellar:

/usr/local/bin/git -> ../Cellar/git/2.34.1/bin/git

Close your terminal, and open it again.

Now if you run which git you can see that the brew one is in use:

/usr/local/bin/git

Upvotes: 7

ElMatador
ElMatador

Reputation: 586

I also did a brew install git.

After doing a git version I knew that I had 2 versions installed.

after an echo $PATH I noticed that path brew installs to was already there.

I closed my terminal window and opened up another one. fix

Now the git version command shows the correct version.

a which git command tells me I am now using the brew version.

Problem fixed.

Upvotes: 2

Pankaj Saini
Pankaj Saini

Reputation: 1648

It is the usual case of keeping 2 software versions for some specific use cases if we may have.

If you will fire "git" in your terminal then the executable which will be present first in your PATH variable will get executed.

You can check your PATH by doing -

echo $PATH

You can also do

which git 

to get to know from where it is getting executed. For git which comes with Mac OSX it is - "/usr/bin/git"

Homebrew generally install git at location "/usr/local/bin". If you want to use the version as installed by Homebrew; you need to append that first in your PATH.

export PATH="/usr/local/bin:${PATH}"

in your ~/.bash_profile followed by

source ~/.bash_profile

Upvotes: 7

Related Questions