Skip to content

Configuring modern Bash as the default shell for macOS

Notifications You must be signed in to change notification settings

skyzyx/bash-mac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Configuring modern Bash as the default shell for macOS

This guide uses Upgrade to bash 4 in Mac OS X as its base, then modifies its content over time, as appropriate. A huge thanks to @hiljaa.

Install Bash

Bash version can be queried with the --version flag:

$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.

The actual installation is going to happen with Homebrew, a macOS package manager.

brew install bash

After that, grab the value from the following command. This is where Homebrew installed your new Bash binary.

$ echo $(brew --prefix bash)/bin/bash
/usr/local/opt/bash/bin/bash

Note

The path above is correct for Intel-based Macs. If you have an Apple Silicon-based Mac, the path will be /opt/homebrew/opt/bash/bin/bash.

Testing the Bash version

Now we'll want to test our version of Bash. Imagine a file:

#! /bin/bash
# version-test.sh
echo $BASH_VERSION;

Make it executable and run it:

$ chmod +x ./version-test.sh
$ ./version-test.sh
3.2.57(1)-release (x86_64-apple-darwin16)

Seemingly it’s still using the old version of Bash. The trick is the shebang on the first line, it’s pointing to the old Bash path. Change it to use the new path that you saved, above.

Intel Mac

#! /usr/local/opt/bash/bin/bash
# version-test.sh
echo $BASH_VERSION;

Apple Silicon Mac

#! /opt/homebrew/opt/bash/bin/bash
# version-test.sh
echo $BASH_VERSION;

Check the version

Now run it and it gives a newer version.

$ ./version-test.sh
5.2.21(1)-release

Configure the Default Shell in Terminal

Again, use the new path that you saved above.

sudo bash -c "echo $(brew --prefix bash)/bin/bash >> /etc/shells"
chsh -s $(brew --prefix bash)/bin/bash

Now quit Terminal, then re-launch it.

echo $BASH_VERSION;

Troubleshooting

If it still shows the old Bash, just go to the Terminal menu → PreferencesGeneralShells open with, then choose Default login shell.

See Also…

About

Configuring modern Bash as the default shell for macOS

Topics

Resources

Stars

Watchers

Forks