• HashiCorp Developer

  • HashiCorp Cloud Platform
  • Terraform
  • Packer
  • Consul
  • Vault
  • Boundary
  • Nomad
  • Waypoint
  • Vagrant
Vagrant
  • Install
  • Intro
  • Tutorials
  • Documentation
  • Vagrant Cloud
  • Try Cloud(opens in new tab)
  • Sign up
Quick Start

Skip to main content
9 tutorials
  • What is Vagrant?
  • Install Vagrant
  • Initialize a Project Directory
  • Install and Specify a Box
  • Boot an Environment
  • Synchronize Local and Guest Files
  • Share an Environment
  • Rebuild an Environment
  • Teardown an Environment

  • Resources

  • Tutorial Library
  • Community Forum
    (opens in new tab)
  • Support
    (opens in new tab)
  • GitHub
    (opens in new tab)
  1. Developer
  2. Vagrant
  3. Tutorials
  4. Quick Start
  5. Synchronize Local and Guest Files

Synchronize Local and Guest Files

  • 2min

  • VagrantVagrant

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 ...

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.

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.

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.

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.

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.

 Previous
 Next

On this page

  1. Synchronize Local and Guest Files
  2. Explore the synced folder
  3. Test the synced folder
  4. Next Steps
Give Feedback(opens in new tab)
  • Certifications
  • System Status
  • Terms of Use
  • Security
  • Privacy
  • Trademark Policy
  • Trade Controls
  • Give Feedback(opens in new tab)