How to change bash versions on Mac with Homebrew

emcain profile image Emily Cain (@data_bae) ・3 min read

MacOS comes with bash 3 as the default shell program; Apple doesn't want to upgrade to the later versions for intellectual property reasons. This means that some features of later versions of bash, like associative arrays, are not available with the default shell. You can always install later versions yourself, however.

Setting up my Mac to run a different version of bash in the terminal was surprisingly hard for me to figure out how to do; it's a pretty straightforward process but I didn't see any one resource describing the entire thing from start to finish, so I'm doing it here.

This is based on my own experience installing bash 5.0.16, using Homebrew 2.2.7, on MacOS Mojave 10.14.6. If this doesn't work for you, let me know in the comments (including the versions of bash, Homebrew, and MacOS), and what if anything did end up working. I'd love to make it applicable to more people.


This tutorial assumes some basic familiarity using the terminal on Mac.

You should have the Homebrew package manager installed -- see this article for instructions.

There's some basic editing with vim -- this article contains everything you need here, but it's basically just knowing i for "insert" and esc+ :wq + return to save changes.

Check your current version

Verify that you have the old version installed currently:


Install the latest bash version using Homebrew

Use $ brew install bash to install the latest version (or specify a version). Take note of where in the filesystem the cask is located, you'll see a message like this:

==> Pouring bash-5.0.16.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/bash/5.0.16: 150 files, 9.4MB

Take a look at that folder:

$ ls /usr/local/Cellar/bash/5.0.16
AUTHORS         NEWS            changelog
CHANGES         NOTES           include
COPYING         README          lib
INSTALL_RECEIPT.json    bin         share
$ ls /usr/local/Cellar/bash/5.0.16/bin
bash    bashbug

The full path to the shell we want is (in this case) /usr/local/Cellar/bash/5.0.16/bin/bash. Make a note of it for the next step.

Set the default shell

There are two steps to changing this. First, find the "shells" file and edit it:

$ atom /etc/shells  # or whatever your preferred text editor is

Add the full path (in this case /usr/local/Cellar/bash/5.0.16/bin/bash) to the end of the list of shells, then save and quit. This will tell your computer that it is safe to use that shell (it's a safety measure to prevent people from accidentally setting random programs as their default shell and breaking everything).

Back in your command line, use the "change shell" command:

$ chsh
Changing shell for <user>.
Password for <user>:

Enter your password. You'll then get file like this in Vim:

# Changing user information for <user>.
# Use "passwd" to change the password.
# Open Directory: /Local/Default
Shell: /bin/bash
Full Name: 
Office Location:
Office Phone:
Home Phone:

Change the entry after "shell" to the new shell path, then save and exit.

Check installation

You may need to open a new terminal window or tab for this to work.


🥳 Yay! 🥳 You can now use new features from bash 4 and 5. And you can always put the default shell back using chsh if you want.

Posted on Jun 24 '18 by:

emcain profile

Emily Cain (@data_bae)


web developer + security engineer. Python, SQL, JavaScript, Go


markdown guide

For what it's worth, you can set /usr/local/bin/bash in /etc/shells then use that path so that if you upgrade bash to a new release you don't have to bother with updated /etc/shells and changing your user's shell.