Vagrant is one of those tools that you may have heard about before but just have not used yet, but once you decide to use it, it will probably end up in your tool belt.

The motivation behind using Vagrant is creating reproducible, portable virtual environments and can quickly be brought up and disposed of at will. Now, that sounds like something that developers would love and they certainly do, but IT professionals can leverage Vagrant too, especially in DevOps. For instance, have you ever wanted to quickly bring up a test VM to test out a script on? Well with Vagrant you can do that with a few commands. Even better, Vagrant can create your virtual machines on Virtualbox, VMware, Hyper-V, AWS and more.

In this article, I will walk you through installing your first Vagrant box from Vagrant cloud, which is a public repository of boxes you can install for free. I will demonstrate installing the box on a Mac, but you can use Vagrant with Windows and Linux as well as your host. Since Vagrant boxes are virtual machines, your local platform actually does not matter at all. The intentions of this article is to get your feet a little wet with Vagrant, but as you dive deeper into the tool, you will find you can do so much more.

Installing Vagrant

You can install Vagrant from its official site here, but I prefer to use homebrew on my Mac to install packages when possible. If you have not used homebrew before, I highly recommend.

Wow that was easy! Now we just need to install Virtualbox, which we also can do with homebrew:

At this point Vagrant and Virtualbox are installed and we are ready to download and install some boxes.

Installing a CentOS Vagrant Box

Now it is time for some Vagrant magic. Here, I want to install a CentOS virtual machine. A quick search for “CentOS” on Vagrant Cloud leads me to the box here. For the sake of simplicity, I will show you a very quick way to bring up a Vagrant box. First, I create a directory that will hold the Vagrant configuration data. To interact with this particular box with Vagrant commands, you must either use the id or we must be in this directory. I prefer to just work in the directory.

Now, I can initialize the box with the command vagrant init:

This command creates a file in my working directory called “Vagrantfile”.  Inside this Vagrantfile there are just three uncommented lines but keep in mind you can configure many other options such as networking, providers and memory:

This is the quick and dirty way to bring up a box in Vagrant without adding any additional configuration to it.

Now it is time to download and install the box, for this we need just one command vagrant up.


Leave a Reply

Your email address will not be published. Required fields are marked *