Vagrant is a tool for building and managing virtual machine environments. It provides a simple workflow for creating reproducible development environments using providers like VirtualBox, VMware, and Docker.
📑 Table of Contents
Key Features
- Reproducible: Consistent environments across team
- Multi-Provider: VirtualBox, VMware, Docker, AWS
- Provisioners: Shell, Ansible, Chef, Puppet
- Synced Folders: Shared files between host and guest
- Networking: Port forwarding and private networks
Installation
Install Vagrant:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vagrant
Usage Examples
Vagrantfile configuration:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "./code", "/var/www"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
config.vm.provision "shell", inline: "apt update && apt install -y nginx"
end
Benefits
Vagrant eliminates “works on my machine” problems. Developers share identical environments, reducing setup time and debugging effort.
Was this article helpful?