Using Vagrant to quickly and easily configure virtual machines

Modern open source software development frequently involves lots of software downloads and machine configuration.  I use my Mac laptop to tinker and learn new programming languages and frameworks.  

For example, say I want to learn Node.js.  Anything I install on my laptop, I'll have to live with indefinitely.  I'd rather leave my laptop alone and work in a virtual machine.  Before learning about Vagrant a couple of years back, I would have launched VirtualBox, created a new machine, and started from there.  But launching VirtualBox in the traditional manner with a GUI consumes over 1 gigabyte of my laptop's memory.  I don't need a gui, I just need to ssh into a machine.  Launching VirtualBox and switching in and out of its windowing is a pain.  I just want a server.  

Vagrant allows me instead to work from the command line and quickly and easily create and ssh into a new machine.  I just have to learn a few simple commands, I don't have to launch the VirtualBox interface and remember where all the menu commands are, or find them if they've changed.

Technically, Vagrant is a wrapper around the VirtualBox API, and it runs on Windows, Mac or Linux.  Simple vagrant commands create, lauch, stop, destroy, and allow me to ssh into a vm.  Vagrant uses a Vagrantfile, which is a small text file containing instructions on how to build a virtual machine: what linux distribution to use, how to map ports, which folders to share with the host, etc.  People create and share Vagrantfile's via GitHub and other means.  

So back learning Node.js: I'm pretty good at installing sofware, but I'd prefer to focus on writing software.  If I'm going to install something like Node.js, I'd prefer to do this based upon instructions from someone that uses Node.js alot and can provide an installation template that includes any little details I might overlook.

So I Google for "vagrant node.js" and immediately find several examples of Vagrantfile's for installing Node.js, e.g. https://github.com/semmypurewal/node-dev-bootstrap.  Assuming I've already installed VirtualBox and Vagrant, then I simply type vagrant up in the same directory as the Vagrantfile.  This will create the virtual machine, enter the machine and do any software installation specified in the Vagrantfile.  To connect to the machine, type vagrant up.  If I want to understand what the Vagrantfile is going to do, I just read it.  Most Vagrantfile's typically contain less than a couple of dozen lines of substantive instructions.  Sharing tiny text Vagrantfile's is much easier than downloading a gigabyte VM, which was a common practice before Vagrant.  Downloading a full VM also obscures what was done to build that VM.  With a Vagrantfile I can easily tweak the installation in any way.

Another benefit of building VM's in this manner is that Vagrant starts with typically very minimal base images for Linux operating systems.  This forces the developer to install whatever is needed -- this is a good thing because it forces you to know exactly what versions of libraries and software you're working with.

Vagrant is not limited to running its VM's on VirtualBox.  There are other "providers" like AWS, VMWare.  So for example you can get your VM configured and tested on your laptop using VirtualBox, and then go to the office and run it on AWS with a couple of minor tweaks.

Here's an example of a project using a Vagrant VM for standing up a Linux VM on VirtualBox with Apache Spark.  You can see how apt-get is updated, and the Java JDK and Spark are installed.  This is just a simple example.  Configurations can be much more complex and can include DevOps tools like Puppet and Chef.  Vagrant now also supports Docker containers.  Vagrant has a plugin system that allows developers to extend its capabilities.