The Solution

Alright that was the problem. What’s the solution? Virtualization of course.

I have come across two interesting projects that address this issues. One of them is vagrant(www.vagrantup.com) and the other is docker (https://www.docker.io/). I will be covering docker in a later blog post.

So… vagrant. hmm..

From vagrant’s homepage, its description states:

Create and configure lightweight, reproducible, and portable development environments.

So how does this work? Basically vagrant runs a headless virtual box vm under the hood. everything runs in an isolated environment. Thus you can have lets say multiple rails apps on your system using different versions of ruby with no collision in between. Plus anytime you feel like it, you can just destroy your vm and recreate it from scratch, without affecting your system.

So why is vagrant powerful ? Well, first of all its completely cli based. You can create a vm, setup ram, harddrive everything from the command line itself.

Secondly its super simple to use. Just by using a simple command, vagrant up you can automatically create your vm, setup networking etc

Thirdly, since everything runs in a vm, Moreover it works exactly the same across linux, osx or windows. So no more cases of “but it works on my machine”

What makes vagrant most powerful is that you can use Vagrantfiles to export and distribute the development environment for your project. This means you will be including a Vagrantfile containing the config of your project along with your project source. Anyone else can just clone your project, run vagrant up (and wait for like 10 mins while the vm is being created) adn start coding.

So whats a normal workflow with vagrant like?

Checkout a project. Lets say https://github.com/rails/rails-dev-box because you want to start contributing to rails Run vagrant up ssh into your vagrant machine using vagrant ssh. And Done!!! You can just clone the rails source, run a quick bundle install and start coding away.

Wait hold on. What if i am not a command line freak like you and want to use sublime text instead of vim?

First of all, you should not call people freaks. That’s mean. Secondly vagrant has the concept of synced folders so all the changes you make in your local machine automatically appear in the vm. Moreover vagrant automatically setups networking for you so you don’t have to do any extra configuration to let’s say test out your latest website in your local browser.

Alright now time for my tea break. I will be covering Vagrantfiles and exporting your project’s dev environment in a separate blog post. In the meantime, make sure you check out vagrant (www.vagrantup.com)