更新Mac OS 10.7的抓握

问题描述 投票:4回答:3

我想将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的参考书(可能类似,我知道);第二,更重要的是,我想学习如何更新这些程序只是为了有效地管理我自己的系统。

macos grep administration
3个回答
5
投票

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

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

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

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

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

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

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

./configure --help

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

0
投票

最近它变得更容易了:

brew install grep

这导致如下行:

==> 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"

然后你会用:

ggrep --color=auto

你以前在哪里执行grep。

© www.soinside.com 2019 - 2024. All rights reserved.