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.
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ## ... Output truncated ...
SSH into your virtual machine to see the synched file.
$ vagrant ssh Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-58-generic x86_64) ## ... Output truncated ...
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@vagrant:~$ ls /vagrant Vagrantfile
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.
To see the files sync between the guest machine and yours add a new folder in your virtual machine's vagrant directory.
vagrant@vagrant:~$ touch /vagrant/foo
End your SSH session.
vagrant@vagrant:~$ exit logout Connection to 127.0.0.1 closed.
List the contents of your local vagrant directory, and notice that the new directory you created on your virtual machine is reflected there.
$ ls Vagrantfile foo
The folder "foo" is now on your host machine; Vagrant kept the folders in sync.
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.