Vagrant Cheatsheet


Here’s a cheat sheet for Vagrant.

Entering vagrant in the command line reveals all available commands.

Ensure you’re in the directory containing the Vagrantfile before executing these commands!

Basic Commands

  • vagrant: Display a list of all available commands. Ensure you’re in the directory with the Vagrantfile.
  • vagrant init: Initialize a new Vagrant environment by creating a Vagrantfile.
  • vagrant init <boxpath>: Initialize with a specific base box. Find boxes in the Vagrant box catalog.

Managing VMs

  • vagrant up: Start your Vagrant environment. Provisions the VM only on the first run.
  • vagrant suspend: Pause the virtual machine, saving its current state.
  • vagrant halt: Stop the VM, similar to shutting down a physical computer.
  • vagrant destroy: Remove all traces of the VM from your system. Use -f to bypass confirmation.
  • vagrant provision: Manually provision the VM, applying configuration changes.
  • vagrant reload: Restart the VM. Use --provision to force provisioning on restart.
  • vagrant resume: Resume a suspended VM. vagrant up can also be used for this purpose.

Interaction

  • vagrant ssh: Securely log into the VM via SSH. Use vagrant ssh <boxname> if you’ve named your box in the Vagrantfile.

Boxes

  • vagrant box list: View installed boxes on your system.
  • vagrant box add <name> <url>: Download a box image to your system.
  • vagrant box outdated: Check if installed boxes are up to date.
  • vagrant box remove <name>: Remove a box image from your system.
  • vagrant box update: Update the base box used by a running VM.

Snapshots

  • vagrant snapshot save <name>: Save the current state of the VM, allowing rollback. Often, vm-name is default.

Utilities

  • vagrant -v: Get the version of Vagrant installed on your system.
  • vagrant status: Show the current status of the VM.
  • vagrant global-status: List status of all Vagrant environments on the system. Use --prune to remove invalid entries.
  • vagrant provision --debug: Increase the verbosity of output for troubleshooting.
  • vagrant up --provision | tee provision.log: Force provisioning while logging output to a file.
  • vagrant push: Deploy code as configured in your Vagrantfile.

Plugins

  • Install Host Updater: Automatically update your /etc/hosts file when starting/stopping your Vagrant box.
vagrant plugin install vagrant-hostsupdater

Notes

  • Use plugins like vagrant-vbguest for guest additions and optimizations.
  • In environments like VVV, enable xdebug by SSH into the VM and running xdebug_on.
  • To start Vagrant with a specific file, place the Vagrantfile in the desired directory, add the box, initialize, and run vagrant up.
comments powered byDisqus