Installed GNU grep on OSX, but can't use

To make GNU grep the default install it with --with-default-names:

$ brew install grep --with-default-names

If you already have it installed use reinstall instead of install.

Ensure that /usr/local/bin (the location of GNU grep) is before /usr/bin (the location of the BSD grep) in your $PATH; which seems to be the case here.

You might have to start a new shell session afterward because Bash caches the binaries paths for the current session. This means that the first time you use grep it’ll determine which binary it’ll use depending on your $PATH and cache it. The next time it’ll use the cached value so changing your $PATH won’t change anything until you reload the shell.


Offically out of date for the answer above.

As of Homebrew version 2.0.0 the --with-default-names flag is no longer available.

from the official documentation

--with-default-names is no longer supported. It is now installed into its own directory and you will need to adjust your PATH to use it.

What you need to do is to add this command to your shell

PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"

Tags:

Path

Homebrew