> ## Documentation Index
> Fetch the complete content index at: https://smallsharpsoftwaretools.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Install GNU Utilities on macOS


macOS systems are based on BSD, rather than on GNU/Linux like RedHat, Debian, and Ubuntu. As a result, a lot of the command line tools
that ship with macOS aren't 100% compatible.

However, using [Homebrew]({{< ref "homebrew" >}}), you can fix that.

### What You Need

To complete this tutorial, you'll need Homebrew installed, which you can do by following the [Install Homebrew]({{< ref "homebrew" >}}) tutorial.

### Installing `coreutils`

The [`coreutils`](http://en.wikipedia.org/wiki/GNU_Core_Utilities) package contains GNU versions of many tools, including `date`, `cat`, and many more.

```command
brew install coreutils
```

To make these commands override their BSD counterparts, modify your `.bash_profile` file to include the path, and then apply the changes to your current environment.

```command
echo 'export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"' >> ~/.bash_profile
```

```command
source ~/.bash_profile
```

Verify that the new `date` command is available by using the `which` command to verify that the `date` command comes from the `coreutils` package:

```command
which date
```

You'll see output similar to the following:

```
/usr/local/opt/coreutils/libexec/gnubin/date
```


## Installing `diffutils` and `findutils`

The [`diffutils`](https://www.gnu.org/s/diffutils/) package includes programs that let you see differences between files, like `diff`, `cmp`, and `diff3`. These exist on your Mac,

Install them with:

```command
brew install diffutils
```

These commands will be placed in `/usr/local/bin`, which should override the built-in tools due to how Homebrew modifies your `PATH`.

The [`findutils`](https://www.gnu.org/software/findutils/) package includes `find`, `locate`, `updatedb`, and `xargs`.

```command
brew install findutils
```

Like `coreutils`, you'll need to add these to your `$PATH` variable. Execute the following line:


```command
echo 'export PATH="$(brew --prefix findutils)/libexec/gnubin:$PATH"' >> ~/.bash_profile
```

Reload your configuration:

```command
source ~/.bash_profile
```

Verify that the changes worked by checking the `xargs` command:

```command
which xargs
```

You'll see output similar to the following:

```
/usr/local/opt/coreutils/libexec/gnubin/date
```

### Installing GNU Versions of `awk`, `sed`, and `grep`

The `awk`, `grep`, and `sed` programs included on macOS work differently than their GNU counterparts.

Install the GNU version of `awk` with:

```command
brew install awk
```

This installs to `/usr/local/bin`, overriding the built-in BSD version.

Install the GNU version of `sed` with this command:

```command
brew install gnu-sed
```

This installs the command `gsed`. To use it in place of your existing `sed` command, add it to your `PATH` by modifying your `.bash_profile` file again, and applying the changes to your local environment:

```command
echo 'export PATH="$(brew --prefix gnu-sed)/libexec/gnubin:$PATH"' >> ~/.bash_profile
```

```command
source ~/.bash_profile
```

Install `grep` with:

```command
brew install grep
```

Like `sed`, `grep` installs as `ggrep`, so if you want it to override your existing `grep` command, add it to your `PATH` in both your `.bash_profile` and your current session:

```command
echo 'export PATH="$(brew --prefix grep)/libexec/gnubin:$PATH"' >> ~/.bash_profile
```

## Installing More Recent Tools

Your Mac comes with versions of Vim, Git, and Less that aren't as up-to-date as you might like. Use Homebrew to install those too:

```command
brew install vim git less
```

You now have the most essential GNU versions of popular utilities.

