🏰 Vagrant

Updated at 2014-09-16 03:42

Vagrant provides lightweight and portable development environments.

Let's say you write web applications and your usual toolset is
Laravel + PostgreSQL + Redis. The problem is that setting these up
on every development environment is tidious and error prone in some cases
e.g. Windows vs. OS X vs. Ubuntu.

With Vagrant, you can setup a development environment in 4 steps:
1. Install VirtualBox.
2. Install Vagrant.
3. Get the project source code e.g. with git.
4. Run `vagrant up` in the project root, which also runs configuration tool.

Using Vagrant efficiently requires using configuration management software. Configuration management software specifies what packages are installed and what configuration steps are taken when a new machine is installed. You can use most configration automation tools with Vagrant but I suggest using Ansible or Puppet. Using them helps you to install and update your software on a live server later.

# With the right configuration, database setup and database seeding,
# resetting your application becomes this easy:
vagrant destroy -f
vagrant up

Vagrant has boxes, image for the virtual machine. Vagrant box is a virtual machine image with Linux, package manager, SSH, a pre-defined user for Vagrant possibly configuration management software. You can extend publicly available base boxes or create your own.

Use custom or extended box per project type. You should create a custom Vagrant box to speed up development environment boot speed. Consider basing the box of a public and popular Vagrant box so it's not required for development. Vagrant box is like a virtual machine image.

# Start a Vagrant instance and connect to it:
vagrant up
vagrant ssh

# Do stuff you want to save to this box:
apt-get update

# Save to changes to a new box:
VBoxManage list vms # Find virtual machine name
vagrant package --base VM_NAME --output

# Add box to your local Vagrant:
# Check what boxes you have: `vagrant box list`
# You can remove, Vagrant stores the box.
vagrant box add --name BOX_NAME

# Use your box in a Vagrantfile.
# = "BOX_NAME"

Note that 64-bit virtual machines might not work if you have Hyper-V enabled on Windows.

Windows Features
-> Disable Hyper-V