更新grep for Mac OS 10.7

Gre*_*ory 4 macos grep administration

我想将Mac上的grep更新到2.5.1以后的更新版本,它与Mac OS 10.7.2一起提供.我的问题是:更新Mac的grep(或任何类似程序)的最佳方法是什么?我可以使用Fink或MacPorts来安装新版本并设置我的路径变量以查看文件树的相应分支,或者我可以更新usr/bin中的grep程序,或者可能还有另一种我没有考虑过的方法.因为我对命令行和Mac的Unix后端相对较新,所以我担心会破坏某些东西.也就是说,我当然愿意从源代码编译最新的grep稳定版本并将其安装在/ usr/bin中,如果这是合适的方法.如果有人想知道我为什么要从2.5.1更新grep,我有两个原因:第一,我正在学习使用grep和基于2.5.3的参考书(可能类似,我知道); 第二,更重要的是,我想学习如何更新这些程序只是为了有效地管理我自己的系统.

Phy*_*ist 6

以下是来自http://www.heystephenwood.com/2013/09/install-gnu-grep-on-mac-osx.html的非常优雅的解决方案

# Enable dupe and install
brew tap homebrew/dupes
brew install homebrew/dupes/grep
# Install the perl compatible regular expression library

brew install pcre

# Add the symlink to a place in $PATH
ln -s /usr/local/Cellar/grep/2.14/bin/ggrep /usr/bin/ggrep
# Add an alias
alias grep="ggrep"

# Verify you got it!
$ grep --version

grep (GNU grep) 2.14
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
# If you want it to be permanent, you can add the alias line to your ~/.bash_profile
# You probably want the alias to stick after reboots
echo 'alias grep="ggrep"' >> ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)


Mac*_*ade 5

如你所说,你可以使用Fink,MacPorts等...

但是如果你只想更新grep,你可能想要获取源代码并进行编译.

如果您决定使用此选项,请不要将其安装在/ usr/bin中.

如果这样做,您将覆盖操作系统所需的内容.
因此,对于另一个版本,您可能会遇到问题,因为操作系统将会出现另一个版本.

而且,如果您这样做,在更新操作系统时会遇到问题,因为它可能会覆盖您自己的版本.

因此,如果要编译它,请将其放入/usr/local/bin(通常使用该--prefix选项),并更新路径环境变量.
这是安全的方式.

通常情况下,编译这样的程序是公正的标准./configure,makesudo make install东西.
但请务必先输入以下内容来查看编译选项:

./configure --help
Run Code Online (Sandbox Code Playgroud)

  • +1.不要替换OS grep.`〜/ bin`或`〜/ local/bin`是另一个不错的选择 (4认同)

phy*_*att 5

最近变得容易了:

brew install grep
Run Code Online (Sandbox Code Playgroud)

这会导致如下所示的行:

==> Installing dependencies for grep: pcre
==> Installing grep dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.43.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre-8.43.high_sierra.bottle.tar.gz
  /usr/local/Cellar/pcre/8.43: 204 files, 5.5MB
==> Installing grep
==> Downloading https://homebrew.bintray.com/bottles/grep-3.3.high_sierra.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring grep-3.3.high_sierra.bottle.2.tar.gz
==> Caveats
All commands 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/grep/libexec/gnubin:$PATH"
==> Summary
  /usr/local/Cellar/grep/3.3: 21 files, 880.7KB
==> Caveats
==> grep
All commands 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/grep/libexec/gnubin:$PATH"
Run Code Online (Sandbox Code Playgroud)

然后你会使用:

ggrep --color=auto
Run Code Online (Sandbox Code Playgroud)

任何您之前执行过 grep 的地方。