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/Option | Example | Description |
---|
vagrant init | vagrant init hashicorp/bionic64 | Initialize a new Vagrant environment with a Vagrantfile |
vagrant up | vagrant up | Create and configure guest machines according to the Vagrantfile |
vagrant halt | vagrant halt | Halt the running Vagrant machine |
vagrant destroy | vagrant destroy | Destroy the Vagrant machine |
Box Management
#
Command/Option | Example | Description |
---|
vagrant box add | vagrant box add hashicorp/bionic64 | Add a box to Vagrant from a box catalog or URL |
vagrant box list | vagrant box list | List all boxes installed on your system |
vagrant box remove | vagrant box remove hashicorp/bionic64 | Remove a box from Vagrant |
vagrant box outdated | vagrant box outdated | Check if there are updates for the box |
SSH and Networking
#
Command/Option | Example | Description |
---|
vagrant ssh | vagrant ssh | SSH into the running Vagrant machine |
vagrant ssh-config | vagrant ssh-config | Output SSH configuration details for connecting to the machine |
vagrant port | vagrant port | Display the guest machine port mappings |
Synced Folders
#
Command/Option | Example | Description |
---|
config.vm.synced_folder | config.vm.synced_folder "./data", "/vagrant_data" | Define a synced folder in the Vagrantfile |
Provisioning
#
Command/Option | Example | Description |
---|
config.vm.provision | config.vm.provision "shell", inline: "echo Hello, World" | Provision the machine using inline shell scripts or other provisioners in the Vagrantfile |
Plugins
#
Command/Option | Example | Description |
---|
vagrant plugin install | vagrant plugin install vagrant-vbguest | Install a Vagrant plugin |
vagrant plugin list | vagrant plugin list | List installed Vagrant plugins |
vagrant plugin uninstall | vagrant plugin uninstall vagrant-vbguest | Uninstall a Vagrant plugin |
Multi-Machine
#
Command/Option | Example | Description |
---|
config.vm.define | `config.vm.define “web” do | web |
Environment Management
#
Command/Option | Example | Description |
---|
vagrant status | vagrant status | Check the status of the Vagrant environment |
vagrant global-status | vagrant global-status | List all active Vagrant environments on the system |
vagrant reload | vagrant reload | Restart the Vagrant machine and apply any changes in the Vagrantfile |
vagrant suspend | vagrant suspend | Suspend the Vagrant machine (saving the state) |
vagrant resume | vagrant resume | Resume a suspended Vagrant machine |
Miscellaneous
#
Command/Option | Example | Description |
---|
vagrant validate | vagrant validate | Validate the Vagrantfile syntax |
vagrant package | vagrant package --output package.box | Package the running Vagrant machine into a box |
vagrant version | vagrant version | Display 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.