Vagrant — Reproducible VM Development Environments
Practical guide to Vagrant — VM-based development environments with Vagrantfile, boxes, providers, provisioning and snapshots on the command line.
Vagrant by HashiCorp builds reproducible development environments as full virtual machines – not containers. The entire configuration lives in a single file, the Vagrantfile, which you version alongside your project. Prebuilt boxes serve as the base images, and Vagrant boots them through a provider such as VirtualBox, VMware, Hyper-V or libvirt. A single vagrant up gives every team member the exact same environment. This guide walks you through the essential commands – from initializing through provisioning to snapshots.
Initialize & Start
vagrant init <box> — Create a Vagrantfile for a specific box.
vagrant init ubuntu/jammy64vagrant up — Start and provision the VM.
vagrant upvagrant up --provider=<name> — Start with a specific provider.
vagrant up --provider=vmware_desktopvagrant up --no-provision — Start without running provisioners.
vagrant up --no-provisionvagrant reload — Restart the VM (applies Vagrantfile changes).
vagrant reloadvagrant reload --provision — Restart and re-run provisioners.
vagrant reload --provisionStop & Destroy
vagrant halt — Gracefully shut down the VM.
vagrant haltvagrant halt -f — Force shutdown the VM.
vagrant halt -fvagrant suspend — Suspend the VM (save state to disk).
vagrant suspendvagrant resume — Resume a suspended VM.
vagrant resumevagrant destroy — Stop and delete the VM completely.
vagrant destroyvagrant destroy -f — Force destroy without confirmation.
vagrant destroy -fSSH & Status
vagrant ssh — Connect to the VM via SSH.
vagrant sshvagrant ssh -c '<command>' — Run a command inside the VM via SSH.
vagrant ssh -c 'cat /etc/os-release'vagrant ssh-config — Show SSH config (for use with ssh command).
vagrant ssh-config >> ~/.ssh/configvagrant status — Show status of the current VM.
vagrant statusvagrant global-status — Show status of all Vagrant VMs system-wide.
vagrant global-statusvagrant port — Show port mappings for the VM.
vagrant portProvisioning
vagrant provision — Run provisioners on a running VM.
vagrant provisionvagrant provision --provision-with <name> — Run only a specific provisioner.
vagrant provision --provision-with shellvagrant upload <src> <dest> — Upload a file to the VM.
vagrant upload config.yaml /home/vagrant/config.yamlBox Management
vagrant box list — List all installed boxes.
vagrant box listvagrant box add <name> — Download and add a box.
vagrant box add ubuntu/jammy64vagrant box update — Update the box for the current environment.
vagrant box updatevagrant box remove <name> — Remove a box from local storage.
vagrant box remove ubuntu/focal64vagrant box outdated — Check if the box is outdated.
vagrant box outdatedvagrant package --output <file> — Package the current VM into a reusable box.
vagrant package --output mybox.boxSnapshots
vagrant snapshot save <name> — Take a named snapshot of the VM.
vagrant snapshot save before-updatevagrant snapshot restore <name> — Restore a snapshot.
vagrant snapshot restore before-updatevagrant snapshot list — List all snapshots.
vagrant snapshot listvagrant snapshot delete <name> — Delete a snapshot.
vagrant snapshot delete before-updatevagrant snapshot push — Take a quick snapshot (stack-based).
vagrant snapshot pushvagrant snapshot pop — Restore and delete the last pushed snapshot.
vagrant snapshot pop Conclusion
Vagrant shines wherever you need a complete, isolated environment – a different operating system, a kernel module or a setup that is awkward to reproduce with containers. Once your Vagrantfile is in place, onboarding a new team member is a single command. For lightweight, purely Linux-based services, containers are often the leaner choice; for reproducible VM environments, Vagrant remains the tool to reach for.
Further Reading
- Vagrant – official documentation – reference and handbook by HashiCorp
- Vagrant Cloud – box catalog – ready-made boxes to plug in
- Vagrant (software) – Wikipedia – background and history
Related Commands
- ddev – container-based local development environments for PHP projects
- docker – build and run containers instead of full VMs
- docker-compose – orchestrate multiple containers declaratively