Skip to main content
Vagrant | Cheatsheets

Quick References #

Creating a VM #

Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you’ll need to specify a base image in the Vagrantfile.

vagrant init
vagrant init <boxpath>` 

Starting a VM #

Starts vagrant environment (also provisions only on the FIRST vagrant up) #

vagrant up

Resume a suspended machine (vagrant up works just fine for this as well) #

vagrant resume

Forces reprovisioning of the vagrant machine #

vagrant provision

Restarts vagrant machine, loads new Vagrantfile configuration #

vagrant reload

Restart the virtual machine and force provisioning #

vagrant reload --provision

Getting into a VM #

Connects to machine via SSH #

vagrant ssh

If you give your box a name in your Vagrantfile, you can ssh into it with boxname. Works from any directory. #

vagrant ssh <boxname>

Stopping a VM #

stops the vagrant machine #

vagrant halt

suspends a virtual machine (remembers state) #

vagrant suspend

Cleaning Up a VM #

Stops and deletes all traces of the vagrant machine #

vagrant destroy

Same as above, without confirmation #

vagrant destroy -f

Boxes #

List of all installed boxes #

vagrant box list

Download a box image to your computer #

vagrant box add <name> <url>

Check for updates vagrant box update #

vagrant box outdated

Deletes a box from the machine #

vagrant boxes remove <name>

Packages a running virtualbox env in a reusable box #

vagrant package

Saving Progress #

vm-name is often default. Allows us to save so that we can rollback at a later time #

vagrant snapshot save [options] [vm-name] <name>

Tips #

get the vagrant version #

vagrant -v

outputs status of the vagrant machine #

vagrant status

outputs status of all vagrant machines #

vagrant global-status

same as above, but prunes invalid entries #

vagrant global-status --prune

use the debug flag to increase the verbosity of the output #

vagrant provision --debug

vagrant can be configured to deploy code!

vagrant push
  • vagrant up --provision | tee provision.log – Runs vagrant up, forces provisioning and logs all output to a file

Plugins #

  • vagrant-hostsupdater : $ vagrant plugin install vagrant-hostsupdater to update your /etc/hosts file automatically each time you start/stop your vagrant box.

Notes #

  • If you are using VVV, you can enable xdebug by running vagrant ssh and then xdebug_on from the virtual machine’s CLI.