I have to update git to the latest version. I updated the brew version of git to latest one and used the unlink command. I have the xcode version installed as well. I have tried setting up the path variables but am not able to update the order of path variables to pick up
I did that using the "brew upgrade git"
brew upgrade git
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################### 100.0%
Warning: git 2.47.0 already installed
I ended the terminal and opened a new one. Now when I check the version, I am getting
git --version
git version 2.39.5 (Apple Git-154)
I checked the locations of git using which, and got the below results
which -a git
/usr/bin/git
/opt/homebrew/bin/git
/usr/bin/git
When I check the PATH using echo, I am getting "/usr/bin/git" before "/opt/homebrew/bin/git"
/usr/bin:/usr/local/bin:/opt/homebrew/bin:
I want to use the git in homebrew, but am not able to do that. I tried updating the order of the locations taking reference from this article. https://codewithsusan.com/notes/path-variable-mac
I found the directories to be located in "sudo nano ~/.bashrc" But after updating, ending the terminal and opening again I still get the paths as
tr ':' '\n' <<< $PATH
/usr/bin
/usr/local/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
I am not able to understand what I am missing, so that git command picks up the brew installed one.
OK, let's debug this. We first need to ask a set of questions.
$PATH
is set.zsh
, not bash
> echo $SHELL
> /bin/zsh
The above is what I would expect to see. Can you confirm this?
On macOS, type
is preferred over which
- it provides more detailed information about how the shell interprets a command. type
can identify whether a command is an alias, a shell function, a built-in, or an external executable. It shows how the shell will interpret the command. My system returns (I set it to do this):
> type git
git is an alias for noglob git
git is /usr/bin/git
git is /opt/homebrew/bin/git
> git --version
git version 2.39.5 (Apple Git-154)
Let's modify the $PATH to see if we can fix this.
> export $PATH=/opt/homebrew/bin/git:$PATH
> type git
git is an alias for noglob git
git is /opt/homebrew/bin/git
git is /usr/bin/git
> git --version
git version 2.47.0
If your system is running zsh
, i.e. $SHELL
returns zsh
then you need to look in:
~/.zshrc
: The most common file for user-specific Zsh configuration. The $PATH is often modified here.~/.zprofile
: This file is executed at the start of a Zsh login shell. $PATH can also be modified here, though typically a less likely culprit.now if $SHELL
returns bash
, then you need to look in:
~/.bash_profile
: This file is executed for login shells. It is a common place to set or modify the $PATH.~/.bashrc
: Executed for interactive non-login shells. It's often used to customize the shell environment.~/.profile
: This file is used if ~/.bash_profile is not present. It can also be used to set or modify $PATH for login shells.~/.bash_login
: Executed for login shells if ~/.bash_profile is not found. It's less commonly used but can still modify the $PATH.My gut feeling is that once you determine your shell, you can debug this.
Zsh Startup Files -- https://zsh.sourceforge.io/Intro/intro_3.html
Bash Startup Files -- https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html