Then create a vagrant configuration file (Vagrantfile), which specifies the image to use. Vagrant calls images Boxes, and they are found over at hashicorp. Make sure that you choose a libvirt image, and not the default VMware.

This config will spin up a Ubuntu based image with two ports forwarded and execute the install script when it is first created. To re-run the provisioning script (install.sh) simply call vagrant provision.

The install file is project specific, and in this case it updates the package manager and installs node and PostgreSQL. It then changes to the shared folder and installs all the dependencies for the node project. Contents of install.sh:

/vagrant is mapped to the relative path of where the Vagrantfile is stored. This is normally stored in the git repository for the project. You will need to run vagrant rsync-auto to sync the changes between the VM and the host.

And that’s it Vagrant in a nutshell. All that’s left to do is start the VM:

vagrant up

It will update and install the software as specified in the install script.