How to use bash as default shell
I am running El Capitan 10.11.3 with bash version 3.x so I decided to update bash via:
brew install bash
Brew places the new bash under /usr/local/Cellar/bash:
brew info bash
bash: stable 4.3.42 (bottled), devel 4.4-beta, HEAD
Bourne-Again SHell, a UNIX command interpreter
https://www.gnu.org/software/bash/
/usr/local/Cellar/bash/4.3.42 (59 files, 7.3M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/bash.rb
==> Dependencies
Required: readline ✔
==> Caveats
In order to use this build of bash as your login shell,
it must be added to /etc/shells.
As you can see brew mentions that I need to update /etc/shells
in order to use the new bash. But after closing/reopening the current shell bash --version
tells me that now I am already using 4.3.42 so I wonder what happened under the hood that the new version is automatically used?
You can use the chsh command to change your shell. In your case, with brew generated bash, you should set it to /usr/local/bin/bash
. You should also put this in /etc/shells
.
As to your question echo $BASH_VERSION
will tell you the version of the current shell. bash --version
tells you the version of the first bash in your $PATH
. So the way you were looking at the version was not telling you the version that you were running.
brew install bash
sudo nano /etc/shells
# add to last line
/usr/local/bin/bash
# save and quit via kntrl + x
Now, you need to see something like this:
cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/usr/local/bin/bash # we added this!
Now set your default shell:
chsh -s /usr/local/bin/bash $USER # this will set for the current user.
Now quit Terminal and re-open it! Check if all ok?
echo $BASH_VERSION # 4.3.42(1)-release