5 Ways to Install Git on Mac with a few commands
About 256 wordsLess than 1 minuteNovember 21, 2024
Using Homebrew
Homebrew is a popular package manager for macOS. If we don't have Homebrew installed, we can install it using:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, we can install Git with:
brew install git
Using MacPorts
MacPorts is another package management system for macOS. If we don't have MacPorts installed, we can install it using:
sudo port selfupdate
sudo port install git
Using Xcode
Apple ships a binary package of Git with Xcode. If we have Xcode installed, we can use it to install Git:
xcode-select --install
Using a Binary Installer
We can download a binary installer for Git from the official Git website. After downloading, we simply run the installer and follow the instructions.
Building from Source
If we prefer to build Git from source, we can download the source code from the official Git website and compile it:
tar -xzf git-*.tar.gz
cd git-*
make prefix=/usr/local all
sudo make prefix=/usr/local install
Verifying the Installation
To verify that Git is installed correctly, we can check the version:
git --version