Official Apple Updates For Bash
OS X bash Update 1.0 – OS X Mavericks | |
OS X bash Update 1.0 – OS X Lion | |
OS X bash Update 1.0 – OS X Mountain Lion |
Alternative to Apple Bash
Warning: proceed with caution. This is for advanced users. This will involve manipulating system files.
First, check which version of bash your Mac is running and if it is not 4.3.x then proceed:
1
2
3
|
$ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
|
Normal Installation
First you’ll need to install homebrew, a package manager for Mac OS X:
1 |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
Update Homebrew and install bash as follows:
1
2
|
$ brew update
$ brew install bash
|
Once Homebrew has finished installing bash, it should be version 4.3.27 or higher.
1
2
3
4
5
6
7
|
$ bash --version
GNU bash, version 4.3.27(1)-release (x86_64-apple-darwin13.4.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
|
You may need to remove and install an updated readline:
1
2
3
|
$ brew rm -f readline
$ brew install readline
$ brew link readline --force
|
Now backup the existing version of bash and create a symbolic link to the Homebrew bash:
1
2
3
4
|
$ sudo mv /bin/bash /bin/bash.3.2.51.bk
$ sudo rm /bin/sh
$ sudo ln -s /usr/local/bin/bash /bin/bash
$ sudo ln -s /usr/local/bin/bash /bin/sh
|
TIP: I recommend that if you previously installed bash through Homebrew, uninstall and remove any previous bash versions in the Cellar directory before installing the latest version. This is reduce any complications that might occur.
Troubleshooting
If you run into the following:
1
2
3
|
dyld: Library not loaded: @@HOMEBREW_PREFIX@@/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/bash
Reason: image not found
|
Then you need to open the Terminal – Preferences and use the backed up version of bash:
Then quit Terminal and start it again.
You will need to enter the following:
1
2
3
|
$ brew rm -f readline
$ brew install readline
$ brew link readline --force
|
Once readline is installed quit Terminal and start it again. Then change the shell path back to Default in Terminal – Preferences – Shell Opens With. Quit Terminal and start it again.
Bash Didn’t Update
Check the bash version to make sure it is 4.3.27 or higher:
1
2
3
4
5
6
7
|
$ bash --version
GNU bash, version 4.3.27(1)-release (x86_64-apple-darwin13.4.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
|
If the bash version did not update:
1
2
3
|
$ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
|
Go back in preferences change shell path back to the backup version of bash in Terminal – Preferences – Shell Opens With as shown in Troubleshooting.
Restart Terminal.
Then you need to uninstall Homebrew bash:
1 |
$ bash uninstall bash |
Next go to cd /usr/local/Cellar/ and run rm -rf bash.
Now install bash again:
1 |
$ brew install bash |
Change Terminal – Preferences – Shell Opens With once again back to Default. Restart Terminal.
Assuming you still have the symbolic links to /usr/local/bin/bash , checking bash version should return:
1
2
3
4
5
6
|
GNU bash, version 4.3.27(1)-release (x86_64-apple-darwin13.4.0)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
|
Further reading about bash, Homebrew, and the “shellshock” bug:
- Bash
- Homebrew
- CVE-2014-6271
- Further flaws render Shellshock patch ineffective
- Bash bug: apply Florian’s patch now (CVE-2014-6277 and CVE-2014-6278)
Revision:
Clarified steps for troubleshooting and to install homebrew.