Vagrant

Vagrant Cheatsheet #

Vagrant is an open-source tool for building and managing virtual machine environments in a single workflow. It provides a simple and easy-to-use command-line client for managing these environments, and it focuses on automation to improve the development workflow.

Basic Commands #

Command/OptionExampleDescription
vagrant initvagrant init hashicorp/bionic64Initialize a new Vagrant environment with a Vagrantfile
vagrant upvagrant upCreate and configure guest machines according to the Vagrantfile
vagrant haltvagrant haltHalt the running Vagrant machine
vagrant destroyvagrant destroyDestroy the Vagrant machine

Box Management #

Command/OptionExampleDescription
vagrant box addvagrant box add hashicorp/bionic64Add a box to Vagrant from a box catalog or URL
vagrant box listvagrant box listList all boxes installed on your system
vagrant box removevagrant box remove hashicorp/bionic64Remove a box from Vagrant
vagrant box outdatedvagrant box outdatedCheck if there are updates for the box

SSH and Networking #

Command/OptionExampleDescription
vagrant sshvagrant sshSSH into the running Vagrant machine
vagrant ssh-configvagrant ssh-configOutput SSH configuration details for connecting to the machine
vagrant portvagrant portDisplay the guest machine port mappings

Synced Folders #

Command/OptionExampleDescription
config.vm.synced_folderconfig.vm.synced_folder "./data", "/vagrant_data"Define a synced folder in the Vagrantfile

Provisioning #

Command/OptionExampleDescription
config.vm.provisionconfig.vm.provision "shell", inline: "echo Hello, World"Provision the machine using inline shell scripts or other provisioners in the Vagrantfile

Plugins #

Command/OptionExampleDescription
vagrant plugin installvagrant plugin install vagrant-vbguestInstall a Vagrant plugin
vagrant plugin listvagrant plugin listList installed Vagrant plugins
vagrant plugin uninstallvagrant plugin uninstall vagrant-vbguestUninstall a Vagrant plugin

Multi-Machine #

Command/OptionExampleDescription
config.vm.define`config.vm.define “web” doweb

Environment Management #

Command/OptionExampleDescription
vagrant statusvagrant statusCheck the status of the Vagrant environment
vagrant global-statusvagrant global-statusList all active Vagrant environments on the system
vagrant reloadvagrant reloadRestart the Vagrant machine and apply any changes in the Vagrantfile
vagrant suspendvagrant suspendSuspend the Vagrant machine (saving the state)
vagrant resumevagrant resumeResume a suspended Vagrant machine

Miscellaneous #

Command/OptionExampleDescription
vagrant validatevagrant validateValidate the Vagrantfile syntax
vagrant packagevagrant package --output package.boxPackage the running Vagrant machine into a box
vagrant versionvagrant versionDisplay the current Vagrant version and check for updates

This cheatsheet covers the most commonly used Vagrant commands and options, helping you to manage boxes, environments, SSH connections, synced folders, provisioning, plugins, and more effectively.

Vagrant

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.