Setting up bash4 as your shell on macos

September 05, 2021

Why change

Default shell for macos since Catalina is zsh. It’s due to licencing - since the newest version of bash is licensed under GPLv3, Apple cannot use it. I’ve been running zsh since then but my drive towards tools that come out of the box has led me go see about setting up bash. I’ve been reading the pure bash bible and working on a few admin scripts and I thought it may be fun to set up my computer to run bash.

Installation

The process is actually quite simple. Remember that it’s not directly possible to actually replace bash with a newer version, so what we will have to do is to install it separately.

Via homebrew, just grab bash:

brew install bash

Assuming your homebrew bin is in your path, you should be able to use it in your scripts by simply stating it in the shebang line:

1 #!/usr/local/bin/bash
2 # <your script contents... >

Why not go a step further and actually set it as a default login shell.

The /etc/shells file is a vfile that lists valid login shells. Add the path to bash to the list there.

Now run the command to choose the default shell. Notice the path checks out with where homebrew installed bash for us.

chsh -s /usr/local/bin/bash

The last step for me was to ensure that tmux is running bash instead of zsh. To accomplish that, I have set default-shell in my .tmux.conf to point to bash too.

The end

Congratulations, in those few steps you’ve changed your macos shell back to bash. Give yourself a little pat on the back and get back to setting all the .rc files. That dry cold prompt ain’t gonna set itself up.


Written by Daniel Kaczmarczyk, a software engineer and educator. you can find me on twitter or email me at daniel.kaczmarczyk@hey.com

a pale blue and yellow circle