# Vagrant — Portable Development Environments Made Simple > Vagrant is a tool for building and managing portable development environments. Define your environment in a Vagrantfile, run vagrant up, and get a fully configured virtual machine — ensuring every developer works in an identical environment. ## Install Save as a script file and run: # Vagrant — Portable Development Environments Made Simple ## Quick Use ```bash # Install Vagrant (requires VirtualBox or similar) # macOS brew install vagrant # Create and start a VM mkdir my-project && cd my-project vagrant init ubuntu/jammy64 vagrant up vagrant ssh # You are now inside the VM ``` ## Introduction Vagrant makes development environments reproducible and disposable. Before Docker, Vagrant solved the "works on my machine" problem by letting teams define entire virtual machines in a single Vagrantfile. Run "vagrant up" and everyone gets the same OS, packages, and configuration — regardless of whether they use macOS, Windows, or Linux. With over 27,000 GitHub stars, Vagrant remains essential for scenarios where containers are not sufficient — testing on different operating systems, running full system stacks, or developing software that needs kernel-level access. It supports VirtualBox, VMware, Hyper-V, and cloud providers. ## What Vagrant Does Vagrant manages virtual machine lifecycles: creating VMs from base images (boxes), provisioning them with shell scripts, Ansible, Chef, or Puppet, synchronizing local files into the VM, and networking for seamless access. The Vagrantfile defines everything declaratively, and can be version-controlled with your project. ## Architecture Overview ``` [Vagrantfile] Declarative VM config (Ruby DSL) | [Vagrant CLI] up, halt, destroy, ssh, provision, status | [Provider] +-------+-------+ | | | [VirtualBox] [VMware] [Cloud] Local VMs Local VMs AWS, Azure Free Licensed DigitalOcean | [Provisioners] Shell, Ansible, Chef, Puppet, Docker | [Synced Folders] Local files <-> VM NFS, rsync, SMB ``` ## Self-Hosting & Configuration ```ruby # Vagrantfile — multi-machine setup Vagrant.configure("2") do |config| # Web server config.vm.define "web" do |web| web.vm.box = "ubuntu/jammy64" web.vm.network "private_network", ip: "192.168.56.10" web.vm.network "forwarded_port", guest: 80, host: 8080 web.vm.synced_folder "./app", "/var/www/app" web.vm.provider "virtualbox" do |vb| vb.memory = 2048 vb.cpus = 2 end web.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y nginx nodejs npm SHELL end # Database server config.vm.define "db" do |db| db.vm.box = "ubuntu/jammy64" db.vm.network "private_network", ip: "192.168.56.11" db.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y postgresql SHELL end end ``` ## Key Features - **Declarative Config** — entire environment defined in a Vagrantfile - **Multi-Provider** — VirtualBox, VMware, Hyper-V, Docker, and cloud - **Provisioning** — shell scripts, Ansible, Chef, Puppet, or Docker - **Synced Folders** — edit locally, run in the VM - **Networking** — port forwarding, private networks, public networks - **Multi-Machine** — define multiple VMs in a single Vagrantfile - **Box System** — pre-built images from Vagrant Cloud - **Snapshots** — save and restore VM state instantly ## Comparison with Similar Tools | Feature | Vagrant | Docker | Nix | Dev Containers | Multipass | |---|---|---|---|---|---| | Isolation | Full VM | Container | Nix store | Container | VM | | OS Flexibility | Any | Linux (host kernel) | Linux/macOS | Linux | Ubuntu | | Resource Usage | Heavy | Light | Light | Light | Moderate | | Startup Time | Minutes | Seconds | Seconds | Seconds | Seconds | | Use Case | Full OS testing | App isolation | Reproducible builds | IDE integration | Quick VMs | | Learning Curve | Low | Low | High | Low | Very Low | ## FAQ **Q: Vagrant vs Docker — which should I use?** A: Docker for application containerization and microservices. Vagrant when you need a full operating system, different kernels, or system-level testing. Docker is lighter and faster; Vagrant provides stronger isolation. **Q: Is Vagrant still relevant with containers?** A: Yes, for specific use cases: testing on different OS versions, kernel development, security testing, and when full VM isolation is required. Docker cannot simulate different operating systems. **Q: How do I share a Vagrant environment with my team?** A: Commit the Vagrantfile to your repository. Team members run "vagrant up" and get an identical environment. Base boxes are downloaded automatically from Vagrant Cloud. **Q: Can I use Vagrant with Apple Silicon Macs?** A: Yes, but VirtualBox support is limited on ARM. Use VMware Fusion, Parallels, or QEMU-based providers for M1/M2/M3 Macs. ## Sources - GitHub: https://github.com/hashicorp/vagrant - Documentation: https://developer.hashicorp.com/vagrant - Vagrant Cloud: https://app.vagrantup.com/boxes/search - Created by Mitchell Hashimoto (HashiCorp) - License: BUSL-1.1 --- Source: https://tokrepo.com/en/workflows/69552a5c-3702-11f1-9bc6-00163e2b0d79 Author: Script Depot