I am trying to replace the default version of grep: (BSD grep 2.5.1-FreeBSD)
on my mac (Mojave 10.14.6)
and when I run the recommended command to replace the BSD version with the gnu version:
brew install grep --with-default-names
I get the aforementioned error. Anyone seen this and know the workaround?
Homebrew removed --with-default-names
because it was causing issues and support requests, so the specific workflow you ask about has been removed from the project.
A workaround, however, is documented:
Commands also provided by macOS have been installed with the prefix "g". If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
reference: https://github.com/Homebrew/brew/issues/5731
EDIT: On Macs, typically user-based configuration changes go into $HOME/.bash_profile
and that is the location I would suggest.
INFO: There is not normally a Mac "$HOME/.bashrc" (although you could create one and it should work). Alternatively you "could" edit the bashrc for all users using the version found in /etc/profile/bashrc. Just pointing out why you may not see the file -- I still suggest editing your local .bash_profile
for this because that's where you are likely to look, later :-)
Here's an example showing gnubin already installed. Mac users of Bash are probably already familiar with the problem of the build-in date
command not supporting -d
or other options found on Linux or with GNU tools. Anyways, with coreutils installed and PATH updated, now I can use and write Bash scripts without testing if the OS is "darwin" or not..
$ which date
/usr/local/opt/coreutils/libexec/gnubin/date
$ date -d @1583927956
Wed Mar 11 07:59:16 EDT 2020
...if I want to install another GNU tool "in front of" osx's version - for example GNU find
- then I would need to update my $PATH var for that tool also. Each Brew command that you want to be "default" will need PATH modification.
This approach will not harm your system commands. Any Apple-provided scripts won't even have your user's $PATH var loaded, so those scripts will default to the system versions. (This is an additional reason to work with your user's bash_profile, and don't modify any profiles found under /etc).