Vagrant and GNU Core Utilities

I recently had the need to install GNU’s Core Utilities on my mac. After a bit of Googling, the easiest, and most straightforward way to proceed was of course with Brew.

Here’s the steps I took for the installation of the GNU packages:

1) Install coreutils and gnu-sed:

$ brew install coreutils
$ brew install gnu-sed

2) Edit my .bashrc file to add the corresponding paths:

# Add alias for nice color output.
alias ll="ls -lAFh --color"

export PATH=$(brew --prefix coreutils)/libexec/gnubin:$(brew --prefix gnu-sed)/libexec/gnubin:$PATH

# Bonus points for adding the man page references
export MANPATH=$(brew --prefix coreutils)/libexec/gnuman:$(brew --prefix gnu-sed)/libexec/gnuman:$MANPATH

3) Verify:

$ source ~/.bashrc

$ which ls

$ which sed

That’s all there was too it. The commands I needed worked perfectly. That is until I attempted to load up one of my Vagrant boxes. Then that annoying NFS exports prompt came up asking me for my password!? I fixed this before didn’t I?

Vagrant NFS Synced Folders

As most of you know, you can add a little snippet to your /etc/sudoers file so vagrant up doesn’t require your password. It’s in the documentation here, but looks like this for macs:

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports

After some debugging to see what was happening, it became clear what the problem was. Vagrant was running the tee and sed commands from my newly installed GNU packages. Luckily there’s an easy fix:

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_ADD_GNU = /usr/local/opt/coreutils/libexec/gnubin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_REMOVE_GNU = /usr/local/opt/gnu-sed/libexec/gnubin/sed -E -e /*/ d -ibak /etc/exports