I found there is some differences between the utility command I used on the mac OSX and linux. I want to make my experience united.

How could I replace all my mac utilities with GNU utilities?

  • See also apple.stackexchange.com/questions/71119/…. – lhf Nov 9 '12 at 23:44
  • 1
    Here's a guide topbug.net/blog/2013/04/14/… – Dennis Mar 19 '15 at 8:50
  • 11
    I sympathize with your frustrations but I believe that, in the long term, it will cause greater frustration if they are replaced - After seeking to do the same thing I'd recommend using homebrew as mentioned below, and then just learning to use the utilities with a g ( gsed, greadlink, etc ) instead of replacing the system utilities. – cwd Mar 29 '15 at 13:51
  • For grep, see apple.stackexchange.com/questions/193288/… – Dan Pritts Apr 19 '16 at 17:28
  • 1
    I disagree with @cwd, using --with-default-names is only affects the local user. It could be an issue with mac oriented terminal utilities, but if you use homebrew for everything, you might aswell pretend you're using linux. Mixed with iterm2, it's working great for me, I can basically pretend I'm home with my linux boxes. – Ray Foss Jun 30 '17 at 17:39
up vote 172 down vote accepted

This adds symlinks for GNU utilities with g prefix to /usr/local/bin/:

brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep

See brew search gnu for other packages. If you want to use the commands without a g prefix, install the formulas with --default-names (or --with-default-names if your brew version is newer), or add for example /usr/local/opt/coreutils/libexec/gnubin before other directories on your PATH.

$ brew info coreutils
coreutils: stable 8.21
Depends on: xz
/usr/local/Cellar/coreutils/8.20 (208 files, 9.4M)
/usr/local/Cellar/coreutils/8.21 (210 files, 9.6M) *
==> Caveats
All commands have been installed with the prefix 'g'.

If you really need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:


Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:

  • 3
    FWIW, I have a Homebrew Formula that acts as a meta-package for all those great GNU utils: see shiny-and-gnu.rb in github.com/al-the-x/homebrew-mine – AL the X May 13 '14 at 20:47
  • 1
    The first PATH works, but MANPATH failed, why? Is it because I'm using OSX10.10? I echoed $MANPATH, and I got /usr/local/opt/coreutils/libexec/gnuman:, seems original MANPATH wasn't include. After commented out the MANPATH conf in my bashrc, I got nothing by ecoh $MANPATH. And of course, if I use man pwd, I got the BSD manual. How to fix this? – Zen Mar 5 '15 at 15:42
  • 2
    For findutils, you need to add PATH="/usr/local/Cellar/findutils/4.4.2/bin:$PATH" which is not stated in the installation console output. – Sridhar-Sarnobat Apr 28 '15 at 20:09
  • 1
    In addition, to get the right man page for findutils, add this to your $MANPATH /usr/local/opt/findutils/share/man – Christian Long Aug 3 '15 at 19:05
  • 1
    @Zen: the right way to initiate MANPATH so as to keep the default system value is: MANPATH="/usr/local/opt/coreutils/libexec/gnuman:${MANPATH-/usr/share/man}". The key is in the construct ${var-default_value}. – daniel Azuelos Oct 6 '15 at 7:43

Besides brew install coreutils, you may also need to install some other packages, such as gnu-sed, grep:

brew install findutils --with-default-names
brew install gnu-indent --with-default-names
brew install gnu-sed --with-default-names
brew install gnutls
brew install grep --with-default-names
brew install gnu-tar --with-default-names
brew install gawk

The --with-default-names option is optional, turn on this if you really need to use these GNU commands as default ones, or they will be compiled with a g prefix.

Reference: http://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/

  • Could you please summarise the info here and not just provide a link - answers should be standalone with links only for extra information – Mark Apr 15 '13 at 8:36
  • 1
    Welcome to the site. Answers on Ask Different need to be more than just a link. It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. – nohillside Apr 15 '13 at 8:43
  • This comment is very usefull ! But I think that brewdon't provide gnu grep package. But you can use MacPorts too :) – Idriss Neumann Nov 1 '13 at 15:10
  • 1
    brew untap homebrew/dupes; brew tap homebrew/dupes; brew install grep worked for me. – Stefan Schmidt Dec 23 '13 at 3:53
  • 1
    @StefanSchmidt I guess something went wrong with your homebrew. homebrew tap --repair should work as well. – xuhdev Dec 23 '13 at 8:15

I'm not sure that I would recommend replacing them; however, you can install them to a different path and utilize them that way. Overall, if you are coming from Linux and would like access to more "generic" *nix utilities, and a system similar to apt, then I would recommend looking into Macports: http://www.macports.org

It allows, for example, using the latest "generic" GCC, as opposed to/in addition to Apple's included GCC, just as an example.

  • 3
    For instance, tar and zip from Mac OS X know about metadata that the GNU versions do not. – lhf Oct 22 '12 at 17:49
  • 1
    There are Apple supplied apps, which are just GUIs for some command line tools and if you replace them the apps may start behaving strangely, so go with adding, not replacing. – Ɱark Ƭ Oct 23 '12 at 11:56
  • Right; something like Macports adds them, it doesn't replace them. – Jonathan Oct 23 '12 at 12:10
  • If you want to use the GNU utilities by default with MacPorts you can add /opt/local/libexec/gnubin to the front of your PATH environment variable. – markshep Sep 26 '16 at 11:59

I've written a script to do exactly this! The script can be viewed here (or below). However, I can't always guarantee this post will reflect the latest version of the script linked previously.

Upon running the script, Homebrew will be installed (if not already), all the associated GNU utilities will be installed (if not already), and the PATH variable will be built from the installed utilities.


# Install Homebrew (if not already installed)
ruby -e "$(curl -fsSL "\

# Install required packages from Homebrew
brew tap homebrew/dupes
brew install coreutils binutils diffutils ed findutils gawk gnu-indent gnu-sed \
  gnu-tar gnu-which gnutls grep gzip screen watch wdiff wget bash gdb gpatch \
  m4 make nano file-formula git less openssh python rsync svn unzip vim \
  --default-names --with-default-names --with-gettext --override-system-vi \
  --override-system-vim --custom-system-icons

# Empty the .bash_path file that holds GNU paths
> ~/.bash_path

# Build PATH variable script in ~/.bash_path
for i in /usr/local/Cellar/*/*/bin; do
  echo 'export PATH="'$i':$PATH"' >> ~/.bash_path
for i in /usr/local/Cellar/*/*/libexec/gnubin; do
  echo 'export PATH="'$i':$PATH"' >> ~/.bash_path
for i in /usr/local/Cellar/*/*/share/man; do
  echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path
for i in /usr/local/Cellar/*/*/libexec/gnuman; do
  echo 'export MANPATH="'$i':$MANPATH"' >> ~/.bash_path

# Check if .bash_path is being called from .bash_profile
PATCH=`grep "~/.bash_path" ~/.bash_profile`
if [ "$PATCH" == "" ]; then
  # Add Ubuntu-style PS1 to .bash_profile
  cat <<EOF > ~/.bash_profile
export PS1="\[\033[1;32m\]\u@\h\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]# "
  # Add .bash_path to .bash_profile
  echo "source ~/.bash_path" >> ~/.bash_profile
  • Don't you just love the downvotes with no critical comments? Thank you for the script. – Justin Force Nov 30 '15 at 22:14
  • @JustinForce No problem! Thank you for the feedback. – Clay Freeman Dec 1 '15 at 2:29
  • 2
    -1. This scripts does too much magic. All of the .bash_path-mangling is not really necessary if you follow @user495470 and @xuhdev's answers. And changing PS1 is completely out of the scope of this question. – Greg Dubicki Jan 27 '16 at 11:40
  • 1
    @GregDubicki unfortunately, the bash path "mangling" is required for some of these packages. You may check this for yourself. In regard to changing PS1: this script is for personal use. Anyone who wishes to revert it may do so very easily. – Clay Freeman Jan 30 '16 at 5:23

I have written a script that transparently transforms the macOS CLI into a fresh GNU/Linux CLI experience by

  • installing missing GNU programs
  • updating outdated GNU programs
  • replacing pre-installed BSD programs with their preferred GNU implementation
  • installing other programs common among popular GNU/Linux distributions


$ git clone git@github.com:fabiomaia/linuxify.git
$ cd linuxify/
$ chmod +x linuxify.sh
$ ./linuxify.sh install

It also allows you to easily undo everything.

$ ./linuxify.sh uninstall

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.