DEV Community

Mr F.
Mr F.

Posted on • Edited on

Awesome Terminal upgrades - Part One: Upgrade and use a newer version of BASH on macOS

This is part one in the "Awesome Terminal upgrades" series. In this short tutorial we will cover BASH on macOS and how you can upgrade and manage it using Homebrew.

Install Homebrew

The missing package manager for macOS (or Linux)

We will be using Homebrew to manage everything for us, if you don't have it installed, go ahead and do it now!

echo “[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion” >> ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Upgrade and use a newer version of BASH on macOS

As of macOS Catalina, the default shell is set to ZSH.
The default version of BASH on macOS is 3.2 which is ancient!
We'll be installing and using version 5 and making it our default shell instead.

brew install bash
sudo vim /etc/shells
Enter fullscreen mode Exit fullscreen mode

You’ll see some output that looks like this:

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Enter fullscreen mode Exit fullscreen mode

We need to update it:

  1. Use your keypad to go down to the last line and press i to edit this line
  2. Type in /usr/local/bin/bash
  3. Type :wq to writeout the file and quit.

Change your default shell to BASH

sudo chsh -s /usr/local/bin/bash
Enter fullscreen mode Exit fullscreen mode

After that, restart your Terminal to have it take effect.

Make sure BASH knows where to source everything from

In order to make sure all of the above stick and work whenever you fire up a terminal, add this line to the top of your ~/.bash_profile file.

[ -r ~/.bashrc ] && . ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Awesome, your shell is now using BASH managed by Homebrew!
You can update BASH whenever you like, as well as you other Homebrew installs by running:

brew update && brew upgrade
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
gabrielizalo profile image
Gabriel Porras

Does this apply to Ubuntu? Thanks

Collapse
 
0xdonut profile image
Mr F.

I wouldn't use Homebrew on Ubuntu. You are better off using the native apt-get instruction, a quick google search returned this article