Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- 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 <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
  • vagrant resume -- resume a suspended machine (vagrant up works just fine for this as well)
  • vagrant provision -- forces reprovisioning of the vagrant machine
  • vagrant reload -- restarts vagrant machine, loads new Vagrantfile configuration
  • vagrant reload --provision -- restart the virtual machine and force provisioning

Getting into a VM

  • vagrant ssh -- connects to machine via SSH
  • vagrant ssh <boxname> -- If you give your box a name in your Vagrantfile, you can ssh into it with boxname. Works from any directory.

Stopping a VM

  • vagrant halt -- stops the vagrant machine
  • vagrant suspend -- suspends a virtual machine (remembers state)

Cleaning Up a VM

  • vagrant destroy -- stops and deletes all traces of the vagrant machine
  • vagrant destroy -f -- same as above, without confirmation

Boxes

  • vagrant box list -- see a list of all installed boxes on your computer
  • vagrant box add <name> <url> -- download a box image to your computer
  • vagrant box outdated -- check for updates vagrant box update
  • vagrant boxes remove <name> -- deletes a box from the machine
  • vagrant package -- packages a running virtualbox env in a reusable box

Saving Progress

-vagrant snapshot save [options] [vm-name] <name> -- vm-name is often default. Allows us to save so that we can rollback at a later time

Tips

  • vagrant -v -- get the vagrant version
  • vagrant status -- outputs status of the vagrant machine
  • vagrant global-status -- outputs status of all vagrant machines
  • vagrant global-status --prune -- same as above, but prunes invalid entries
  • vagrant provision --debug -- use the debug flag to increase the verbosity of the output
  • vagrant push -- yes, vagrant can be configured to deploy code!
  • 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.
@kiknaio

This comment has been minimized.

Copy link

@kiknaio kiknaio commented Oct 6, 2017

Useful cheatsheet 👍

@bdmbdsm

This comment has been minimized.

Copy link

@bdmbdsm bdmbdsm commented Dec 4, 2017

Thanks!

@dimmo

This comment has been minimized.

Copy link

@dimmo dimmo commented Dec 4, 2017

fix: vagrant boxes remove => vagrant box remove

@zencircle

This comment has been minimized.

Copy link

@zencircle zencircle commented Mar 2, 2018

vagrant global-status (will provide id)
Network changes --> https://stackoverflow.com/questions/28401565/how-can-i-access-a-vagrant-guest-from-another-virtualbox-guest
vagrant reload id

@walkerlala

This comment has been minimized.

Copy link

@walkerlala walkerlala commented Aug 20, 2018

what does "provision" mean in Vagrant?

@MohanSai1997

This comment has been minimized.

Copy link

@MohanSai1997 MohanSai1997 commented Sep 4, 2018

provision means " the action of providing or supplying something for use "
so,
provision in vagrant means
providing a particular machine in vagrant.

@rootkeb

This comment has been minimized.

Copy link

@rootkeb rootkeb commented Feb 11, 2019

very useful thank you !

@ravdevops

This comment has been minimized.

Copy link

@ravdevops ravdevops commented Feb 22, 2019

how to scroll up in vagrant ubuntutrusty64

@dasginganinja

This comment has been minimized.

Copy link

@dasginganinja dasginganinja commented Jun 12, 2019

Plugins: vagrant-cachier, vagrant-auto_network

Also, your vagrant destroy -f line is missing a backtick.

@west0706

This comment has been minimized.

Copy link

@west0706 west0706 commented Jul 28, 2019

Goood! Cheet sheet. Very clearly:)

@zizu1985

This comment has been minimized.

Copy link

@zizu1985 zizu1985 commented Sep 18, 2019

All in one place :) Thanks.

@bsayiner

This comment has been minimized.

Copy link

@bsayiner bsayiner commented Sep 22, 2019

Clear and easy. Thanks

@YoussF

This comment has been minimized.

Copy link

@YoussF YoussF commented Dec 18, 2019

Thank you !

@mjsadri

This comment has been minimized.

Copy link

@mjsadri mjsadri commented Jan 31, 2020

Thanks, it was very useful

@sharanpeetani

This comment has been minimized.

Copy link

@sharanpeetani sharanpeetani commented Mar 18, 2020

Thank you! it's very useful.

@devluis

This comment has been minimized.

Copy link

@devluis devluis commented Mar 21, 2020

Thank you.

@gerroon

This comment has been minimized.

Copy link

@gerroon gerroon commented Apr 24, 2020

Is there a way to search vagrant apps on the command line hosted by hashicorp's pp database?

@AmilcarArmmand

This comment has been minimized.

Copy link

@AmilcarArmmand AmilcarArmmand commented Jun 4, 2020

Very useful. Thank you!

@Almorisson

This comment has been minimized.

Copy link

@Almorisson Almorisson commented Aug 21, 2020

Thanks for this nice cheat-sheet. Sometimes cheat-sheet are more user friendly than some documentation.

@FerJaraG

This comment has been minimized.

Copy link

@FerJaraG FerJaraG commented Sep 16, 2020

thank you!!!

@Mashharawi

This comment has been minimized.

Copy link

@Mashharawi Mashharawi commented Oct 7, 2020

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.