I installed bash-5.1 via Homebrew on my Macbook (M1-Monterey).
sachetz$ /opt/homebrew/bin/bash –version
GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin21.1.0)
Added the path to /etc/shells file:
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/opt/homebrew/bin/bash
And ran the following command to set bash-5.1 as the default:
sachetz$ chsh -s /opt/homebrew/bin/bash
However, when I restart terminal and run the bash --version
command, I still see bash-3.2:
sachetz$ bash –version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.
But if I run echo $BASH_VERSION
, I see bash-5.1
sachetz$ echo $BASH_VERSION
5.1.16(1)-release
Running which bash
gives:
sachetz$ which bash
/bin/bash
Running echo $SHELL
gives:
sachetz$ echo $SHELL
/opt/homebrew/bin/bash
When I run an echo $PATH
with zsh as the default, I see /opt/homebrew/bin:
% echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
However, if I run the same after the chsh to Homebrew bash, I see:
sachetz$ echo $PATH
/Applications/XAMPP/xamppfiles/bin:/Applications/XAMPP/xamppfiles/bin/php:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
I’m guessing the issue here is that /opt/homebrew/bin:/opt/homebrew/sbin
is not present in the $PATH after I switch the default to Homebrew bash and restart the terminal. So the question is, why is the path variable different between the two, and how do I fix the issue?
3
Answers
Just needed to add
/opt/homebrew/bin:/opt/homebrew/sbin:
to the PATH variable in ~/.bash_profile like:I suppose I missed this out as an installation step or something.
You might want to check the profiles, I believe bash checks both
~/.bashrc
and~/.bash_profile
. Typically the $PATH are setup there.For zsh, it looks at
~/.zshrc
.Also, you can check to see Terminal > Preference > Shells open with… option in the Terminal app.
which bash
looks for bash under your path andbash --version
is running a new bash from your path. If your path points to /bin/bash first, they’ll give that bash’s path/version. This isn’t the correct way to verify the current shell’s version.The
$BASH_VERSION
&$SHELL
point to the current shell and looks like it is already running the correct version.You could also try new built-in variables, like