Harness the Combinatoric Power of Command-Line Tools and Utilities
Install GNU Utilities on macOS
Published January 26, 2019 and last verified on September 20, 2025
Introduction
macOS systems are based on BSD, rather than on GNU/Linux like RedHat, Debian, and Ubuntu. As a result, a lot of the command line tools that ship with macOS aren’t 100% compatible.
However, using Homebrew, you can fix that.
What You Need
To complete this tutorial, you’ll need Homebrew installed, which you can do by following the Install Homebrew tutorial.
Installing coreutils
The coreutils package contains GNU versions of many tools, including date, cat, and many more.
brew install coreutilsTo make these commands override their BSD counterparts, modify your .bash_profile file to include the path, and then apply the changes to your current environment.
echo 'export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"' >> ~/.bash_profilesource ~/.bash_profileVerify that the new date command is available by using the which command to verify that the date command comes from the coreutils package:
which dateYou’ll see output similar to the following:
/usr/local/opt/coreutils/libexec/gnubin/date
Installing diffutils and findutils
The diffutils package includes programs that let you see differences between files, like diff, cmp, and diff3. These exist on your Mac,
Install them with:
brew install diffutilsThese commands will be placed in /usr/local/bin, which should override the built-in tools due to how Homebrew modifies your PATH.
The findutils package includes find, locate, updatedb, and xargs.
brew install findutilsLike coreutils, you’ll need to add these to your $PATH variable. Execute the following line:
echo 'export PATH="$(brew --prefix findutils)/libexec/gnubin:$PATH"' >> ~/.bash_profileReload your configuration:
source ~/.bash_profileVerify that the changes worked by checking the xargs command:
which xargsYou’ll see output similar to the following:
/usr/local/opt/coreutils/libexec/gnubin/date
Installing GNU Versions of awk, sed, and grep
The awk, grep, and sed programs included on macOS work differently than their GNU counterparts.
Install the GNU version of awk with:
brew install awkThis installs to /usr/local/bin, overriding the built-in BSD version.
Install the GNU version of sed with this command:
brew install gnu-sedThis installs the command gsed. To use it in place of your existing sed command, add it to your PATH by modifying your .bash_profile file again, and applying the changes to your local environment:
echo 'export PATH="$(brew --prefix gnu-sed)/libexec/gnubin:$PATH"' >> ~/.bash_profilesource ~/.bash_profileInstall grep with:
brew install grepLike sed, grep installs as ggrep, so if you want it to override your existing grep command, add it to your PATH in both your .bash_profile and your current session:
echo 'export PATH="$(brew --prefix grep)/libexec/gnubin:$PATH"' >> ~/.bash_profileInstalling More Recent Tools
Your Mac comes with versions of Vim, Git, and Less that aren’t as up-to-date as you might like. Use Homebrew to install those too:
brew install vim git lessYou now have the most essential GNU versions of popular utilities.