> ## Documentation Index
> Fetch the complete content index at: https://smallsharpsoftwaretools.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use a Modern Bash Shell on macOS


macOS ships with an older version of the Bash shell, because newer versions use a license that makes it more difficult for Apple to integrate into their OS. In macOS Catalina, Apple changed the default shell to ZSH for this reason.

But by using [Homebrew](https://brew.sh), you can install the latest version of Bash and use its features.

## What You Need

To complete this tutorial, you'll need Homebrew installed, which you can do by following the [Install Homebrew]({{< ref "homebrew" >}}) tutorial.

## Finding Your Current Bash Version

First, check your current Bash version:

```command
echo $BASH_VERSION
```

If you see a version like the following, you're running a very old version:

```output
3.2.57(1)-release
```

Use Homebrew to get a newer version.

## Installing the Latest Bash with Homebrew

Ensure you have Homebrew installed, which you can do by following [Installing Homebrew]({{< ref "homebrew" >}}).

Then use Homebrew to install Bash:

```command
brew install bash
```

To see where Homebrew installed Bash, run the following command:

```command
ls "$(brew --prefix)/bin/bash"
```

You'll see a result similar to this:

```command
/usr/local/bin/bash
```

On M1 macs, the path will be `/opt/local/homebrew/bin/bash` instead.

Next, add the path to Homebrew's version of Bash to the `/etc/shells` file. Display the contents of the file to ensure that it's not already listed:

```command
cat /etc/shells
```

You'll see something like this:

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

Use the following command to add the newer version of Bash to the `/etc/shells` file:

```command
echo "$(brew --prefix)/bin/bash" | sudo tee -a /etc/shells
```

Since the file is owned by the administrator, you can't redirect text using standard redirection, but you can work around it by using `tee` to send output to a file as it's run with `sudo`. The `-a` flag appends text rather than overwriting the existing file.

Ensure the file now contains the new shell:

```command
cat /etc/shells
```

You'll find the new shell at the end of the file:

```output
# 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
```

Now you can change your shell.

## Switching to the Newest Bash Shell

To switch shells, use the `chsh` command to change the shell for your user. Use the following command to specify the version you installed with Homebrew:

```command
chsh -s "$(brew --prefix)/bin/bash"
```

The system prompts you for your password. Enter it and your shell will change:

```output
Changing shell for brianhogan.
Password for brianhogan:
```

The current shell doesn't change, so open a new Terminal and use the following command to check your Bash version:

```command
echo $BASH_VERSION
```

You'll see the newer version appear:

```output
5.0.11(1)-release
```

You now have the latest version installed.

To change back to the system-installed version of Bash, use `chsh -s /bin/bash`.

## Conclusion

You've changed your shell to the latest version of Bash, and you know how to change it back to the default. You can use the same approach to install the latest version of ZSH, or other shells like Fish. Install the shell, add the path to its binary to `/etc/shells`, and use `chsh` to switch the shell.

