Installing Bash from Source on macOS

If you are a command line user on macOS, you may have noticed that the bash shell that comes with the system is stuck at version 3, and has been for many years. This article describes how to install and configure the latest bash on macOS.

A quick web search reveals that Apple cannot update bash beyond version 3 due to licensing restrictions. In the meantime, the official version of bash has reached 5.

This situation apparently would have continued, except for the recent announcement that macOS 10.15 Catalina will switch the default shell from bash to zsh.

Supposedly, zsh is not too different from bash. Since zsh is already available on macOS, you can verify whether this is true for your use case, by invoking it interactively:


When I did this, I was immediately greeted with a broken prompt string.

So, if you rely on bash, you now have two reasons to upgrade:

  • So that you can use the latest version
  • Because you will need to manually perform a shell change anyway when using Catalina

Download and unpack the source code

Visit the following page to obtain the source code for bash:

Scroll down the list to see newer versions. As of this writing, the latest distribution is

Unpack the source code into a build directory. For example, if you have saved the package file in ~/Desktop:

cd ~/Desktop
tar xf bash-5.0.tar.gz
cd bash-5.0

Build and install

The build process for bash is an excellent example of how simple installing software from source can be, even without a package manager.

For the context behind the build commands given below, see this article.

./configure --prefix=/opt/bash-5.0
sudo make install
sudo ln -s /opt/bash-5.0 /opt/bash

Change your shell

You now have the latest version of bash at the following path:


You need to change your environment so that you use this new version instead of either /bin/bash or /bin/zsh.

The simplest way to do this is to use the Users & Groups preferences panel, as documented by the Apple support article at the link below.

On that page, scroll down to the section titled From Users & Groups preferences and follow the instructions, but, in the “Advanced Options” dialog, for the Login shell: field, instead of selecting a shell from the menu, type in the path of the shell you want to use, which is /opt/bash/bin/bash.

The following illustrates a correctly specified login shell using that dialog, pointing to our latest version of bash:

Set login shell illustration

After completing this procedure, all new shell sessions you start will run the latest bash. To verify:

echo $SHELL