How to export a Vagrant virtual machine to transfer it

Eugene picture Eugene · Dec 19, 2013 · Viewed 102k times · Source

I have a vagrant box up and running (configured with a LAMP stack). I need to transfer it to another PC. How can I export it? I guess that I can get a file (or files) that can be copied to another PC, so there I can run some command to import the vagrant box.

Answer

Emyl picture Emyl · Dec 19, 2013

You have two ways to do this, I'll call it dirty way and clean way:

1. The dirty way

Create a box from your current virtual environment, using vagrant package command:

http://docs.vagrantup.com/v2/cli/package.html

Then copy the box to the other pc, add it using vagrant box add and run it using vagrant up as usual.

Keep in mind that files in your working directory (the one with the Vagrantfile) are shared when the virtual machine boots, so you need to copy it to the other pc as well.

2. The clean way

Theoretically it should never be necessary to do export/import with Vagrant. If you have the foresight to use provisioning for configuring the virtual environment (chef, puppet, ansible), and a version control system like git for your working directory, copying an environment would be at this point simple as running:

git clone <your_repo>
vagrant up