Vagrant: Vagrantfile, Boxes & Core Commands
Vagrant builds and manages portable, reproducible development environments as virtual machines, defined declaratively via a Vagrantfile. It eliminates 'works on my machine' inconsistencies -- every team member gets an identical VM, regardless of their own host OS.
A Basic Vagrantfile
# Vagrantfile (Ruby syntax, but the project itself can be any language --
# this only configures the VM environment, not the app code)
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64" # base image from Vagrant's box registry
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = 2
end
# Forward the guest VM's port 3000 to localhost:3000 on the host
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provision "shell", path: "setup.sh"
endCore Commands
vagrant up # create/start the VM, downloading the box if needed,
# then run provisioning -- typically a new team
# member's entire onboarding step
vagrant ssh # open a shell inside the running VM -- SSH keys are
# managed automatically, no manual setup needed
vagrant status # check whether the VM is running, halted, or
# not yet created
vagrant halt # gracefully shut down, preserving disk state --
# like powering off a laptop
vagrant destroy # completely remove the VM and its disk -- requires
# a full re-provision to recreate
vagrant reload # restart the VM (halt + up), preserving disk state --
# needed after changing network/provider settings
vagrant provision # re-run provisioning on an ALREADY-RUNNING VM,
# without a restart -- for picking up script changesSynced Folders
By default, the project directory containing the Vagrantfile is automatically mounted inside the VM. Edits made on the host machine in a regular editor are immediately reflected inside the VM -- the application runs in the VM against those same, live-synced files.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free