A versão 1.1 do Vagrant foi lançada. A documentação que você está lendo é para o Vagrant 1.0.x. Leia mais sobre o Vagrant 1.1 no anúncio de lançamento. Acesse agora a documentação da versão 1.1.

config.vm.share_folder

Configuration key: config.vm.share_folder

This directive is used to configure shared folders on the virtual machine and may be used multiple times in a Vagrantfile. Shared folders specify folders that are on the host machine that become available on the guest machine, so that edits on either side are immediately visible on both the host and the guest.

Shared folders are easy to configure:

Vagrant::Config.run do |config|
  # ...
  config.vm.share_folder "foo", "/guest/path", "/host/path"
end

The above would create a shared folder mapping named “foo” (a logical name), from “/host/path” on the host to “/guest/path” on the guest. The host path can be a relative path, which is expanded relative to the directory where the main project Vagrantfile is.

Additional options may be passed in as an options hash for a 4th parameter. The support options are:

  • :create - If set to true and the host path doesn’t exist, Vagrant will automatically attempt to create it. Default: false
  • :nfs - If set to true, then the shared folder will be shared using NFS. For more information, read about NFS shared folders.
  • :transient - If set to true, then the shared folder definition will not be persisted across restarts.

Additionally, there are certain options that have an effect only on NFS shared folders:

  • :map_uid - The UID that modifications to the shared folder map to on the host machine. By default, Vagrant will use the UID of the owner of the folder.
  • :map_gid - The GID that modifications to the shared folder map to on the host machine. By default, Vagrant will use the GID of the owner of the folder.
  • :nfs_version - This is the NFS version that will be used as the format for the mount.

Caveats

There is a VirtualBox bug related to “sendfile” which can result in corrupted or non-updating files. You should disable “sendfile” in any web servers you have running.

In Nginx:

sendfile off;

In Apache:

EnableSendfile Off