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
/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 --versiontells 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?

  • How did you closing/reopening the current shell ? – mmmmmm Jan 22 '16 at 14:50
  • @Mark right click on terminal icon -> quit, left click on terminal icon – Mike Jan 22 '16 at 14:51

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.

| improve this answer | |
  • Ok I think I understand. But doesn't that mean brew modified my path an put /usr/local/bash to path? Or is /usr/local/bash default in PATH? – Mike Jan 22 '16 at 15:34
  • Ok sudo stat -x /etc/paths tells me that it was not modified by brew (you will need sudo anyway). So it must be default. And I think you are right, after doing your steps echo $BASH_VERSION does now return 4.3.42. Thank Merm! – Mike Jan 22 '16 at 15:51
brew install bash
sudo nano /etc/shells

# add to last line

# 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.

/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
| improve this answer | |
  • might not be obvious this same method also works for zsh and fish shells. – Andy Jan 16 '19 at 0:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .