Synchronize local and guest files
Virtual machines are convenient for developing in, but not many people want to edit files using a plain terminal-based editor over SSH. Vagrant automatically syncs files to and from the guest machine. This way you can edit files locally and run them in your virtual development environment.
By default, Vagrant shares your project directory (the one containing the Vagrantfile) to the /vagrant
directory in your guest machine.
Create and configure a guest machine, as specified by your Vagrantfile.
SSH into your virtual machine to see the synched file.
Explore the synced folder
On the virtual machine, list the files in the vagrant directory.
Tip
When you vagrant ssh
into your machine, you're in /home/vagrant
, which is a different directory from the synced /vagrant
directory.
Believe it or not, the Vagrantfile that you see inside the virtual machine is actually the same Vagrantfile that is on your actual host machine.
If your terminal displays an error about incompatible guest additions (or no guest additions), you may need to update your box or choose a different one. Some users have also had success with the vagrant-vbguest plugin, but it is not officially supported by the Vagrant core team.
Test the synced folder
To see the files sync between the guest machine and yours add a new folder in your virtual machine's vagrant directory.
End your SSH session.
List the contents of your local vagrant directory, and notice that the new directory you created on your virtual machine is reflected there.
The folder "foo" is now on your host machine; Vagrant kept the folders in sync.
Next steps
With synced folders, you can continue to use your own editor on your host machine and have the files sync into the guest machine.
You have successfully interacted with your host machine via synced folders on the guest machine. In the next tutorial, learn about installing packages, users, and more with provisioning.