I'm new to OS X. I'm running OS X Lion on a MacBook Pro. Is it safe to upgrade the bash shell using Homebrew:

$ brew install bash

If safe, how do I make it the default instance of the shell I run through Terminal?


  • 2
    This question has suddenly become extremely relevant, see Shellshock
    – ecnepsnai
    Commented Sep 25, 2014 at 15:56
  • Yes. 10 c h a r s
    – shrx
    Commented Mar 7, 2016 at 9:59
  • @ecnepsnai The problem with Google Search links is that someone visiting after a few years will not see what you saw when you posted the link!
    – P i
    Commented Sep 5, 2023 at 13:03

4 Answers 4


Binaries in /{,usr/}{,s}bin/ should not usually be replaced with other files. Other programs expect them to be the versions that came with OS X, and they are replaced by OS upgrades.

After running brew install bash, you can change the default shell safely by:

  • Adding /usr/local/bin/bash to /etc/shells
  • Running chsh -s /usr/local/bin/bash.

Settings in Terminal or iTerm 2 don't normally have to be changed. Both of them default to opening new windows with a login shell of the default shell.

The default shell can also be changed from System Preferences or with dscl, but all three options just modify /var/db/dslocal/nodes/Default/users/$USER.plist.

  • Looks like it worked, and if I experience any issues it should be easy to roll back! Thanks!
    – Rudy
    Commented Sep 9, 2011 at 21:52
  • 3
    The bit about editing /etc/shells to include the brew-installed bash is required. Otherwise (at least on my machine) Terminal will refuse to start. Commented Feb 20, 2012 at 23:38
  • 2
    The third command (csh -s) appears to no longer be necessary on Mavericks 10.9.2. Commented Apr 1, 2014 at 1:26
  • 3
    I just had to brew install bash for this to work. (i.e. didn't have to modify /etc/shells)
    – Daniel
    Commented Sep 25, 2014 at 7:22
  • 3
    On Apple Silicon Macs, brew packages are installed under /opt/homebrew/ instead of /usr/local/. So /opt/homebrew/bin/bash instead of /usr/local/bin/bash. Commented Dec 22, 2022 at 20:08

I could be wrong here, but as far as I know brew would install it's own instance of bash, since brew works under /usr/local/bin while the system defaults works under /bin (and /usr/bin).

About Terminal, you can make shells open with your own, custom command. Go to Preferences > Startup and select Shells open with: Command (complete path). Simply type the path to your new bash and vuala!

Hope it helps!

BTW: Backup! Best advice in this situations!

  • hey, you know what, this answer actually works like a charm
    – castiel
    Commented Sep 25, 2014 at 6:53

Well before you do anything, back up your current file (of course, but always deserves to be said)

sudo cp /bin/bash /bin/bash.3.2.bk

Then create a symlink to the bash executable that Homebrew downloaded. I think it will be in /usr/local/Cellar, like so

sudo ln -s /usr/local/Cellar/bash/4.2.10/bin/bash /bin/bash

Now /bin/bash points to the file in your usr/local directory

  • 3
    The downside of plopping a new bash in for the system version is any update of the OS can erase your preferred shell. Presumably the OP wants to use new features which could break if the OS installs a "newer than old OS" but "older than custom" version of bash. Better to change the default path or change the user shell variable.
    – bmike
    Commented Sep 9, 2011 at 22:58
  • well, you could just create a new simlink since it wouldn't overwrite the version of bash in your usr/local directory. but you are correct, Daniel's way is prob better Commented Sep 9, 2011 at 23:36
  • Ooh - edit your answer please to put that first (and keep the original idea if you prefer as a second alternative - I like that much better and would love a chance to reverse my vote :-)
    – bmike
    Commented Sep 9, 2011 at 23:38
  • 1
    hmm, well that /is/ what I said, but I edited to try to clarify what each step does a little better. Still think top rated answer is prob better though :) Commented Sep 9, 2011 at 23:44
  • This seems like a pretty dangerous way to go about changing the system shell. Commented Sep 10, 2011 at 0:26

I think it is safe if you just launch

brew install bash

and then add it as your default shell

chsh -s /usr/local/bin/bash

since you are only modifying your current user. However, I noticed that my default ~/.profile is

if [ "/bin/bash" == $BASH ]; then
    source ~/.bashrc

so it needs to be updated. I changed it to

if [ "bash" == $(basename $BASH) ]; then
        source ~/.bashrc
  • See other answers for why chsh alone is not enough. Also it your updated .profile snippet looks identical to the original one
    – nohillside
    Commented Mar 7, 2016 at 9:26
  • @patrix: thanks to point it out, I updated the second snippet. It would be nice if brew install bash would not require any further action. With the updated profile I shared, it does not. I hope this can help others. Commented Mar 8, 2016 at 8:51

You must log in to answer this question.

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