Search for a command to run...
Install Vagrant 2.4.9, add boxes, manage VirtualBox, VMware, Hyper-V and libvirt providers, share folders and provision machines with Ansible or shell scripts.
Vagrant builds and manages reproducible development environments. One Vagrantfile
describes the machine, and Vagrant takes care of creating, provisioning, connecting to
and tearing it down.
Vagrant 2.4.9 · the official HashiCorp apt/rpm repositories ·
Vagrant Box v2 format · providers for VirtualBox, VMware, Hyper-V, libvirt, Docker
and Podman
| Provider | Notes |
|---|---|
| VirtualBox | Free, works everywhere, slower than KVM |
| libvirt / KVM | The fastest option on Linux |
| VMware Workstation / Fusion | Good performance, needs a licence for some features |
| Hyper-V | The built-in option on Windows |
| Docker / Podman | Container-based, no virtual machine |
# Add the HashiCorp signing key
wget -O - https://apt.releases.hashicorp.com/gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Add the repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release || lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/hashicorp.list
# Install Vagrant
sudo apt update
sudo apt install -y vagrant
# Install a provider (VirtualBox is the easiest starting point)
sudo apt install -y virtualbox
vagrant --version# Version
vagrant --version
# List the providers Vagrant can use
vagrant provider --list# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# The box the machine is created from
config.vm.box = "bento/ubuntu-24.04"
# Provider specific settings
config.vm.provider "virtualbox" do |vb|
vb.memory = 4096
vb.cpus = 2
end
# A private network so the host can reach the guest
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.56.10"
# Synchronise the project folder into the guest
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
# Provision with a shell script
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get install -y nginx
SHELL
end# Add the box (downloads it once)
vagrant box add bento/ubuntu-24.04
# Validate the configuration
vagrant validate
# Create and start the machine
vagrant up
# SSH into it
vagrant ssh
# Stop it (keeps the disk)
vagrant halt
# Destroy it (removes everything)
vagrant destroy -fA box is a pre-built base image. The catalogue lives on Vagrant Cloud.
# Search for a box
vagrant search ubuntu
# Add a specific version
vagrant box add bento/ubuntu-24.04 --box-version 20241002
# List the boxes you have
vagrant box list
# Update a box
vagrant box updateA box tag such as bento/ubuntu-24.04 is a moving target. Pin an exact
--box-version in your Vagrantfile so every developer and CI job starts from the
same image.
# Global status
vagrant status
# SSH details for the connection
vagrant ssh-config
# Port forwarding
vagrant port --guest 80
# Run a command inside the machine
vagrant ssh -c "systemctl status nginx"
# Copy a file in or out
vagrant ssh -c "cat /var/log/syslog"
vagrant copy ./file.txt /tmp/file.txt
# Suspend and resume
vagrant suspend
vagrant resumeVagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-24.04"
# Point Vagrant at your Ansible playbooks
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbooks/site.yml"
ansible.compatibility_mode = "2.0"
ansible.extra_vars = { vagrant: true }
end
end# Re-provision an existing machine
vagrant provision --provision-with ansibleVagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-24.04"
config.vm.define "web" do |web|
web.vm.hostname = "web"
web.vm.network "private_network", ip: "192.168.56.10"
end
config.vm.define "db" do |db|
db.vm.hostname = "db"
db.vm.network "private_network", ip: "192.168.56.11"
end
end# Bring up everything
vagrant up
# Bring up one machine
vagrant up web
# Run a command on a specific machine
vagrant ssh db# List the installed providers
vagrant provider --list
# Use a specific provider
vagrant up --provider=libvirtOn Linux, libvirt/KVM is dramatically faster than VirtualBox. On Windows, use Hyper-V. On macOS, VMware Fusion or UTM are the fastest options.
vagrant destroy -f instead of rm -rf .vagrant — it cleans up properly..vagrant directory or a *.box file to Git.vagrant box prune regularly to reclaim disk space.Install Consul 2.0, run a client-server cluster with ACLs and TLS, register services with health checks, and set up service discovery and the service mesh.
Install Packer 1.16, write HCL2 templates, build machine images for AWS, Azure, GCP and QEMU, and produce signed provenance attestations for your supply chain.