Skip to content

Instantly share code, notes, and snippets.

@andre3k1
Created July 26, 2018 18:39
How to install gnu sed on Mac OS X and set it as the default
# Check which version of sed is used when you run the `sed` command
# The version that ships with Mac OS X is
# /usr/bin/sed
which sed
# Install gnu-sed using Homebrew
# The `--with-default-names` option configures `sed` to use gnu-sed
# Without that option, you'll need to type `gsed` to use gnu-sed
brew install --default-names gnu-sed
# Verify which version of sed is used when you run the `sed` command
# OK: /usr/local/bin/sed
# BAD: /usr/local/bin/gsed
# If BAD, run `brew uninstall gnu-sed`, then reinstall with `--with-default-names`
which sed
@divStar
Copy link

divStar commented Oct 30, 2023

For zsh, after installing gnu-sed using brew install gnu-sed, I just added this at the end of the ~/.zshrc:

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

You path may vary and you can acquire it using brew info gnu-sed (as mentioned above). The key is to add it late in the ~/.zshrc. Also note, that if you are using a different shell, you will want to change the path variable in the corresponding configuration file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment