Why Use Vagrant for Development?

Hello Developers and welcome to our series on using Vagrant for development. This is our first article in the series where we’ll discuss what Vagrant is and why we should use it.

At a previous job we had a server for our production workload and then we each set up a local development environment to do our development. To do this we had a rough document that outlined what packages needed to be installed and what changes to make in our configuration files. This process worked well but we constantly had little differences between our environments. Every so often someone would install a vastly different version of a package and use a feature that didn’t exist in the production version of the package. When they deployed their code to production it would break the application and we would have to quickly roll back their changes.

Worse still would be the fact that due to the mismatch in setups a bug in production wouldn’t be reproducible in the developer’s environment and they would waste hours trying to fix it.

By using Vagrant we can quickly and easily set up a development environment with a minimal amount of human involvement.

What is Vagrant?

Vagrant is an open-source product that makes it easy to build and maintain software development environments. It uses hypervisors like VirtualBox and VMware to host the environment and provides a glue layer that allows us to set up the necessary software we need. Vagrant itself is written in Ruby so we may occasionally see references to Ruby and .rb files in the output.

To get started we’ll need to install Vagrant from https://www.vagrantup.com/. We’re using version 2.2.14 for this series and as always using a different version may cause a different set of outputs.

We’ll also need a hypervisor like VirtualBox or VMware Workstation. This article series was written using version 6.1.16 of VirtualBox. VirtualBox is a good way to get started with Vagrant because it’s free and open-source but VMware will give us a better performance.

Why Should We Use It?

There are numerous benefits to using Vagrant to set up our development environment.

  1. Vagrant makes resetting our development environment super easy. This makes it easy to set up a new computer or recover if something is broken.
  2. It helps reduce the “it works on my computer” excuses for bugs. Because we’re using a common setup we can be sure we’re using the same major/minor versions of packages
  3. It provides the “glue” that makes it easier to develop our code such as setting up a shared directory between the host and the guest VM. This allows us to use our favorite GUI applications without having to jump through any extra hoops.

Virtual Machines

The core piece of technology that Vagrant leverages to set up our development environment is the Virtual Machine (VM). VMs are essentially a file that a piece of software known as a hypervisor uses to run an operating system that behaves like a completely separate computer inside another computer.

For more information on virtual machines be sure to check out our article “What’s a Virtual Machine?”.