Sunday, 24 November 2013

Updating Bash

A shell allows you to run commands to interact with your computer, it's the shells job to understand what you have written and to perform an action based on it. When you type "date" for example, the shell looks in all the locations it has stored for an executable called "date", runs it, and shows you the output.

There are various shells that work slightly differentially, but the one that comes default in OS X is Bash. By default OS X mavericks runs bash 3.2, we're going to update it to the latest version 4.2.

Prerequisites 

Before attempting this tutorial you'll need to have homebrew installed.


This tutorial was done with the following versions:
  • Mavericks (10.9)
  • Homebrew (November 2013)

Installation

1. Open a terminal and install bash
brew install bash

Homebrew is pretty easy

Wait until bash has finished installing

Now the latest version of bash is installed, but you still have to configure some things to get your terminal to run the latest version at startup. We need to tell a configuration the location of new version of bash, and we need to run a command to actually change the shell.

Configuration

1. Use this one liner to add "/usr/local/bin/bash" to the end of this file "/etc/shells"

sudo bash -c "echo /usr/local/bin/bash >> /etc/shells"
A few extra steps are required when permissions are needed in directions.

2. Check the file with this command to confirm it was written correctly

cat /etc/shells
/usr/local/bin/bash

The command "chsh" which we'll use in a minute, won't allow you to pick a shell that isn't in this list.


3. Write the following into the terminal, followed by your password to change the default shell.

chsh -s /usr/local/bin/bash

chsh -s /usr/local/bin/bash


4. Close and reopen your terminal

5. Write the following commands in to check if the new shell is running

echo $SHELL
echo $BASH_VERSION

$SHELL and $BASH_VESRION are both environment variables.

End Notes 

Check out some other tutorials about OS X and the terminal.

  • Click here to learn how to add color to your bash prompt (coming soon)
  • Click here for a list of awesome command line utilities (coming soon)

No comments:

Post a Comment