'I want to use Git via macports instead of Apple Git
I'd like to use the latest version Git via macports instead of Apple Git. But when I type git --version
on terminal app, it displays Apple Git version.
Could you tell me how to use the latest version git on Mac?
Solution 1:[1]
I assume that you have xCode and macports installed and properly working. In order to use macports git
first you have to install it:
sudo port install git
And then add this line to your to .profile
file in your home directory:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Something like this echo "export PATH=/opt/local/bin:/opt/local/sbin:$PATH" >> $HOME/.profile"
should do it.
As a last step you must source
the .profile
or .bash_profile
for these changes to take effect like this: source $HOME/.profile
.
To summarize, open the terminal on MacOSX and type:
$ sudo port install git
$ echo "export PATH=/opt/local/bin:/opt/local/sbin:$PATH" >> $HOME/.profile
$ source .profile
$ which git
/opt/local/bin/git
Every time you load the shell the MacPorts path should be available. In case this doesn't work, try using .bash_profile
or .bashrc
to save the environment $PATH variable.
Solution 2:[2]
It's now 2022 and my Mac is using zsh. I wanted to use MacPorts to update git to latest version instead of using Apple Git. I do not use Homebrew.
% git --version
git version 2.30.1 (Apple Git-130)
%which git
/usr/bin/git
% port contents git
Port git is not installed.
So clearly, my computer is using Apple Git. I need to update MacPorts and install git
% sudo port selfupdate
// macports updates
% sudo port install git
// macports installs git
% port contents git
// now lots of files get listed
However, at this point, my computer is still using Apple Git.
% git --version
git version 2.30.1 (Apple Git-130)
%which git
/usr/bin/git
So now I just need to update my ".zshrc" file by adding a new PATH for MacPorts git. MacPorts puts things in "/opt/local/bin", so we need to let our shell know that. Edit the .zshrc with vim (or vi or pico)
% vim ~/.zshrc
With the editor open, add these lines (in there somewhere, just find a good spot [make sure there are no other Git related PATH additions])
# PATH for MacPorts git install
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
Save the file.
At this point, I would suggest just rebooting your console session (you don't need to reboot machine). Alternatively, you could type this line in the console...
source .zshrc
At this point, if all has gone well, you should now be using the latest Git.
% git --version
git version 2.35.3
% which git
/opt/local/bin/git
Luck be with you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | matt |