Updating bash and other tools on Mac OSX

This is a summary how to upgrade bash and other tools to recent versions, performed on macOS Sierra 10.12.6. – credits go to the authors of the links on the bottom of this post.

The versions of Bash and other GNU tools on Mac OS X are old, and need to be updated if you get errors like these:

declare: -A: invalid option
readlink: illegal option -f
sed -i failing

Newer versions of these tools can be installed in /usr/local with HomeBrew.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update

If you get an error like Error: /usr/local must be writable! then use the following lines to grant write permission to the admin group on /usr/local

sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local

Install bash and related tools. (declare is a bash command, readlink is part of coreutils)

brew install bash
brew install coreutils
brew install gnu-sed --with-default-names

Add the following lines to ~/.bash_profile

alias readlink=greadlink
alias declare=gdeclare

# This function is used in $PROMPT_COMMAND
update_terminal_cwd() {
 # Identify the directory using a "file:" scheme URL,
 # including the host name to disambiguate local vs.
 # remote connections. Percent-escape spaces.
 local SEARCH=' '
 local REPLACE='%20'
 printf '\e]7;%s\a' "$PWD_URL"
export -f update_terminal_cwd

This page is a summary of the solutions presented at the following web pages:

Error: /usr/local must be writable! on 10.11.4 Beta (15E61b) #49895
How can I get the behavior of GNU’s readlink -f on a Mac?
Upgrade to bash 4 in Mac OS X – clubmate.fi
osx – sed command with -i option failing on Mac, but works on Linux – Stack Overflow
Bash 4 associative arrays: error “declare: -A: invalid option” – Stack Overflow
macos – What does update_terminal_cwd do in the terminal of OS X – Ask Different


Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s