20

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 --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 ? – user151019 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
8

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.

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

You must log in to answer this question.

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