How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported bash bash

How to use GNU sed on Mac OS 10.10+, 'brew install --default-names' no longer supported


Note (2019):

The --with-default-names option is removed since January 2019, so now that option is not available anymore.

When installing, Homebrew instructs on how to adapt the path, if one wants to use sed without the g prefix.


You already have the gnu-sed installed without the --with-default-names option.

  • With --with-default-names option it installs sed to /usr/local/bin/
  • Without that option it installs gsed

So in your case what you gotta do is:

$ brew uninstall gnu-sed$ brew install gnu-sed --with-default-names

Update path if needed...

$ echo $PATH | grep -q '/usr/local/bin'; [ $? -ne 0 ] && export PATH=/usr/local/bin:$PATH$ echo a | sed 's_A_X_i'

or use gsed as others suggested.


When you install the GNU version of sed for Mac OS X using:

$ brew install gnu-sed

The program that you use is gsed.

So for example:

$ echo "Calimero is a little chicken" > test$ cat testCalimero is a little chicken$ gsed -i "s/little/big/g" test$ cat testCalimero is a big chicken

Also, to compliment the use of GNU command tools on Mac OS X, there is a nice blog post here to get the tools from linux:

Install and use GNU command line tools on Mac OS/OS X


$ brew install gnu-sed

$ export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

With these two commands gnu-sed works properly