π If you have homebrew installed, follow there steps, if not, skip to the second part
1. Confirm existing git
Out of curiosity, if you want to check where your Git is installed, you can type the following in your terminal:
which git
It should return something like: /usr/bin/git
2. Check git version
To check the version of Git you are using, type:
git --version
3. Install Git Using Homebrew
If you want to update your Git version, it's simple if you already have Homebrew installed. Assuming Homebrew is already set up on your system, type the following:
brew install git
This will install the latest version of Git and automatically set it in your PATH, replacing the Apple-provided version.
Now quit and restart your terminal.
4. Confirm Installation Location
To verify where the new version of Git is installed, run:
brew info git
The output should look something like this: Installed
/opt/homebrew/Cellar/git/2.47.1 (1,685 files, 54.4MB) *
You can also check the installed git version and path:
git --version
which git
The output should point to the new version, located at /usr/local/bin/git
or /opt/homebrew/bin/git
.
5. Update PATH to Prioritize the New Git Version
If the output of the above command shows the latest version then you are all set.
β οΈHowever, it's possible that it is still using the previous version.
If macOS continues to use the system-provided /usr/bin/git instead of the new version, you need to prioritize the Homebrew version by updating your PATH.
For Intel Macs:
Add this line to your shell configuration file (e.g., ~/.zshrc, ~/.bashrc):
export PATH="/usr/local/bin:$PATH"
For Apple Silicon Macs:
Add this line instead:
export PATH="/opt/homebrew/bin:$PATH"
Then reload your shell configuration:
source ~/.zshrc
Finally, verify the installed version again:
git --version
If the output shows the latest version, you're all set!
π If you don't have homebrew installed, follow these steps to install homebrew
If Homebrew is not installed, run the following command to set it up:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installation, confirm Homebrew is recognized by running:
brew --version
Set Homebrew Path Variable
If your terminal does not recognize brew
, add Homebrew's bin
directory to your PATH:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
This command appends the line export PATH="/opt/homebrew/bin:$PATH"
to your .zshrc file
, ensuring that the /opt/homebrew/bin
directory is included in your PATH variable.
After running this command, you need to reload your .zshrc file to apply the changes:
source ~/.zshrc
This ensures that the changes take effect immediately without needing to restart your terminal session.
Now you can install Git using Homebrew (see Step 3 above).
Top comments (0)