I'm running FreeBSD 9.1-RELEASE. I've installed GNU grep with portmaster textproc/gnugrep
.
However the "default" grep for users is still FreeBSD grep.
# /usr/local/bin/grep -V
/usr/local/bin/grep (GNU grep) 2.12
# grep -V
grep (GNU grep) 2.5.1-FreeBSD
I want to make GNU grep the default. I understand that the problem is with the order of directories specified in my PATH
environment variable:
# echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
However, I fear to move the /usr/local/bin
entry to the beginning of my PATH
. Is it safe?
In Linux distros like Debian such tasks are usually accomplished via dpkg-divert
and/or update-alternatives
.
What is the best way to do what I want in FreeBSD and not break system upgrades and such?
Best Answer
Update: Note this answer is from 2013, it applies to FreeBSD 8.x and earlier. A BSD grep was added in revision 222273 and appeared in FreeBSD-9.0 (oddly that change is missing from the usually comprehensive release notes: Google search). A fully-featured GNU grep continues to be available in the ports collection.
FreeBSD
grep
iswas GNUgrep
, albeit old and with a few patches applied:It has a small number of patches (most of which originate from Fedora Linux), if you have
/usr/src/
installed those are detailed in/usr/src/gnu/usr.bin/grep/FREEBSD-upgrade
.If you need something specifically in the port version (2.12 vs 2.5.1) there are many bugfixes, speed improvements, and PCRE support (
-P
, not enabled in system version), it should be quite safe to reorder yourPATH
to put/usr/local/bin
first, this is what I usually do. (It's good practise to usesu -
so that root's environment is set correctly, though on FreeBSD the default~root/.cshrc
sets thePATH
explicitly.)Otherwise check your shell man page and set an
alias
as required, but this is really only for interactive use, shell scripts or Makefiles won't observe it.