Search code examples
gitmacosmacports

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

  • 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.