cheat-sheets

Vagrant Cheat-Sheet

Vagrant builds and manages reproducible development VMs from a Vagrantfile.

General Management #

COMMANDDESCRIPTION
vagrant statusOutputs status of the vagrant machine
vagrant global-statusOutputs status of all vagrant machines
vagrant global-status --pruneSame as above, but prunes invalid entries
vagrant versionInstalled version
vagrant validateValidate the Vagrantfile
vagrant plugin listInstalled plugins

Managing VMs #

COMMANDDESCRIPTION
vagrant init <BOX>Create a Vagrantfile for a box, e.g. ubuntu/jammy64. Without a box you must specify one in the Vagrantfile before vagrant up
vagrant upStarts vagrant environment (also provisions only on the FIRST vagrant up)
vagrant haltStops the vagrant machine
vagrant reloadRestart and re-read the Vagrantfile
vagrant suspendSuspends a virtual machine (remembers state)
vagrant resumeResume a suspended machine (vagrant up works just fine for this as well)
vagrant sshConnects to machine via SSH
vagrant ssh <BOXNAME>If you give your box a name in your Vagrantfile, you can ssh into it with boxname
vagrant ssh-configSSH settings, useful for ~/.ssh/config (OpenSSH Cheat-Sheet)
vagrant destroyStops and deletes all traces of the vagrant machine
vagrant destroy -fSame as above, without confirmation

Provisioning VMs #

COMMANDDESCRIPTION
vagrant provisionForces reprovisioning of the vagrant machine
vagrant provision --debugUse the debug flag to increase the verbosity of the output
vagrant up --provision | tee provision.logRuns vagrant up, forces provisioning and logs all output to a file
vagrant up --provision-with <NAME>Run one named provisioner

Manage Boxes #

COMMANDDESCRIPTION
vagrant box listSee a list of all installed boxes on your computer
vagrant box add <BOXNAME> <BOXURL>Download a box image to your computer
vagrant box outdatedCheck for updates
vagrant box updateUpdate the box for the current environment
vagrant box pruneRemove old box versions
vagrant box remove <BOXNAME>Deletes a box from the machine
vagrant packagePackages a running VirtualBox env in a reusable box

Snapshots #

COMMANDDESCRIPTION
vagrant snapshot save <NAME>Save state
vagrant snapshot listList snapshots
vagrant snapshot restore <NAME>Restore
vagrant snapshot delete <NAME>Delete

Example Vagrantfile #

ruby
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/jammy64"
  config.vm.hostname = "dev"
  config.vm.network "private_network", ip: "192.168.56.10"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.synced_folder ".", "/vagrant"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
    vb.cpus = 2
  end
  config.vm.provision "shell", inline: "apt-get update && apt-get install -y nginx"
  # or: config.vm.provision "ansible", playbook: "site.yml"  (see the Ansible Playbooks sheet)
end

Vagrant with WSL2 #

Vagrant is able to run inside your Windows Subsystem for Linux environment (WSL Cheat-Sheet). A tutorial on how to install and use it with your Windows installed Virtualbox can be found here.

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.