Developing software in the Real World

Upgrading to Bash 4 on macOS

Incredibly, macOS Mojave comes with Bash 3.22 by default still. Apparently this is due to licensing reasons, however Bash 4 has lots of lovely features including associative arrays that I’d like use. Hence, after reading the Internet for a bit, I’ve installed it on my Mac. This turned out to require just 3 commands:


Close the terminal and open a new one which now has Bash 4!

Bash4

Using Bash 4 in scripts

Any script that start with #!/bin/bash will continue to use Bash 3, so we use env in the same way as we do with PHP, Ruby or Python scripts and start our Bash script files with:


This will now use Bash 4 when you run the script interactively.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *