Grep update for Mac OS 10.7

I would like to upgrade grep on my Mac to a newer version than 2.5.1, which comes with Mac OS 10.7.2. My question is: what is the best way to update grep (or any similar program) for Mac? I could use Fink or MacPorts to install the new version and set the path variable to search in the corresponding branch of the file tree, or I could update the grep program in usr / bin or maybe another approach that I did not consider, since I'm relatively new to on the command line and on a Mac Unix server, I'm worried about breaking something. However, I would of course be prepared to compile the latest stable release of grep from source code and install it in / usr / bin, if that is the appropriate method. In case anyone wonders why I want to upgrade grep from 2.5.1, I have two reasons: firstly, I am studying the use of grep with a 2.5.3-based directory (probably it seems I know) ; 2nd and, more importantly, I want to learn how to update such programs simply as an effective management of my own system.

Please feel free to direct me to the appropriate link instead (or in addition to), which gives instructions on how to complete the assignment in question.

Thanks in advance, Gregory

+4
source share
2 answers

As you said, you can use Fink, MacPorts, etc.

But if you just want to update grep, you might want to grab the sources and compile them.

If you decide to go with this option, do not install it in / usr / bin .

If you do this, you will overwrite something necessary for your OS.
Thus, with a different version, you may run into problems, since the OS will be with the exception of another version.

And also, if you do this, you will have problems updating the OS, as it may overwrite your own version.

So, if you want to compile it, put it in /usr/local/bin (usually with the --prefix option) and update the path environment variable.
This is a safe way.

Typically, compiling such a program is just standard ./configure , make and sudo make install material.
But first, familiarize yourself with the compilation options by typing:

 ./configure --help 
+5
source

The following is a very elegant solution from 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 
+3
source

Source: https://habr.com/ru/post/1384253/


All Articles