Last Updated: February 25, 2016
· elbcoast

Vagrant: Conditional NFS for Mac/Linux machines

Per default vagrant uses VirtualBox Guest Additions to share your workspace with the vagrant VM. This is okay for Windows machines, but on unixoid hosts this can be quite slow, you should better use NFS here.

Unfortunately, NFS doesn't work out of the box on actual Windows machines. If you are working in a hybrid development environment with Windows and Linux/Mac hosts, you are stuck between a rock and a hard place.

The solution is to use NFS only on machines that support it. The configuration snippet for the VagrantFile looks like this:

if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) == nil
  # Use nfs
  config.vm.network :hostonly, ""
  config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
  # This uses uid and gid of the user that started vagrant
  config.nfs.map_uid = Process.uid
  config.nfs.map_gid = Process.gid

This works for vagrant 1.0.x, but should also work on later versions.