Installed GNU grep on OSX, but can't use

大城市里の小女人 提交于 2019-12-05 05:40:57

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"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!