2011-12-02 108 views
4

我想將我的Mac上的grep更新爲比Mac OS 10.7.2附帶的2.5.1更新的版本。我的問題是:爲Mac更新grep(或任何類似程序)的最佳方式是什麼?我可以使用Fink或MacPorts來安裝一個新版本並設置我的路徑變量以查找文件樹的適當分支,或者我可以更新usr/bin中的grep程序,或者可能還有另一種我沒有考慮過的方法。因爲我對Mac的命令行和Unix後端程序相對比較陌生,所以我擔心打破某些東西。也就是說,我肯定願意從源代碼編譯最新的grep發行版,並將其安裝在/ usr/bin中,如果這是合適的方法的話。如果有人想知道爲什麼我想從2.5.1更新grep,我有兩個原因:第一,我正在學習使用基於2.5.3的參考書(可能類似,我知道)使用grep;第二,更重要的是,我想學習如何更新這些程序,僅僅是爲了有效地管理我自己的系統。正在更新grep for Mac OS 10.7

請隨時指引我,以取代(或除了)提供有關如何完成相關任務的指導的適當參考。

由於提前, 格雷戈裏

+0

更好的一個非常優雅的解決方案superuser.com或apple.stackexchange。 com(他們可能會嘟something fink或macports:http://stackoverflow.com/questions/20853/macports-or-fink) – Thilo

回答

5

正如你所說,你可以使用Fink,MacPorts的,等等

但如果你只是想更新的grep,你可能要搶資源,並編譯它們。

如果您決定使用此選項,請勿將其安裝在/ usr/bin中。

如果你這樣做,你會覆蓋你的操作系統所需要的東西。
所以在另一個版本中,您可能會遇到問題,因爲操作系統將會除另一個版本之外。

此外,如果您這樣做,更新操作系統時會遇到問題,因爲它可能會覆蓋您的版本。

所以,如果你想編譯它,把它放在/usr/local/bin(通常與--prefix選項),並更新你的路徑環境變量。
這是安全的方法。

通常,編譯這樣的程序只是標準的./configure,makesudo make install的東西。
但一定要看一看的編譯選項首先,通過鍵入:

./configure --help 
+4

+1。不要替換操作系統grep。 '〜/ bin'或'〜/ local/bin'是另一個不錯的選擇 – Thilo

+0

@Macmade,我喜歡在'/ usr/local/bin'中從源代碼編譯的選項。我在哪一步使用'--prefix選項'?一旦我知道了,我會閱讀命令的文檔,並給它一個鏡頭。謝謝。 – Gregory

+1

'--prefix'在配置編譯時使用。所以基本上:'./configure --prefix =/usr/local [OTHER OPTIONS]''make''sudo make install'。 – Macmade

3

以下是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