Skip to main content

An Introduction To Vagrant

I spent my Sunday afternoon familiarizing myself with a tool who's Getting Started page has been sitting in my Evernote tickle file for a couple weeks. This is one of those many projects that fall under the ever widening category of "Stuff I Wanted To Do, But Am Glad Someone Else Did It So I Can Just Use It And Get On To The Next Thing." If you use virtual machines as part of your development process, or want to, and especially if you already use the excellent VirtualBoxVirtualBox, then Vagrant is certainly worth looking at.

The Setup (for Vagrant 0.2)


Now, the docs might need some updating and they seem to assume you're already a Ruby user, so they're missing a few dependancies that such a person would just happen to alread have. This is what I did, as an Ubuntu user who didn't even have Ruby installed. I'm also adding Virtualbox's Karmic repository to provide VBox 3.1, which Vagrant requires.

sudo apt-get install rubygems libxslt-dev openssl-ruby
sudo gem install vagrant
sudo bash -c 'echo "deb http://download.virtualbox.org/virtualbox/debian karmic non-free" >> /etc/apt/sources.list'


My machine installed Vagrant to /var/lib/gems/1.8/ so I added /var/lib/gems/1.8/bin/ to $PATH.

Each Vagrant box you build should have its own directory for configuration and should be run from their, so you can create a test project now.

mkdir test-vagrant && cd test-vagrant

Also, there are reports of issues on some 64-bit machines and I couldn't get the base image to run, but the Ubuntu Karmic image is running fine for me, so this got me started with my first Vagrant box:
vagrant-box add karmic http://files.vagrantup.com/contrib/karmic.box
vagrant init
vagrant up

The Point, What Is?

Why do this? What is the value in being able to quickly build, run, and clone virtual machines? Here are a few ways I'm already using them and will use them (more) with a tool like Vagrant to make it nicer.

  • Keeping a definitive base of my development environment. I always have an image of a machine that I consider my minimum requirements for whatever project I might be working on. This is an Ubuntu image with all the tools I use, my vimrc and my virtualenv/pip shortcuts, etc. When I start a new project, I clone this image and add to it.
  • Making my specific environments reproducible. This one I have tried and can now start doing seriously with Vagrant. For any project, I can maintain a script to build a development environment on top of my base. The benefits are two part. First, I can keep a clean record of what is required to work with a project. Second, when a change is made to my base, I can rebuild my development environment for all of my projects instantly. (Well, I can issue the command instantly, but I'll probably each lunch before its done!)
  • VirtualBox images can be portable. It might even be possible to move suspended images, but I'm not completely sure about this, yet. If it turns out to be something I can do, I'll be able to suspend a project on my desktop, running the box off a USB key, and then resume it on my laptop in the park. Even if I can't do this, I can still build identical environments on multiple machines, for myself or for other developers.
  • Replicating production and building local staging setups, machine the setups I have at Linode and EC2, will become something I can do with a minimal effort. I'm going to save a lot of time deploying to clones of my production machines running right here under my desk.

UPDATES:
April 5, 2010 - Added links to Vagrant and VirtualBox websites. Added step to include repository for VirtualBox 3.1

Comments

YHVH said…
Does it also manage the copying of port forwarding ie :22 -> :2222 and :80 -> :8080. I have to set this up on every virtual machine I clone and it would be nice to be able to script
Anonymous said…
@YHVH: What's the port-forwarding for? Some reproduction of how your deployment servers will be?

Oh, or is it something to do with NAT mode? I usually run in bridged mode and just give each of my VMs its own IP (on my RFC 1918 network), so I'm a bit blind to the requirements of NAT mode. To be honest, I'm not really sure what the advantage of NAT mode is.
Marius Gedminas said…
Vagrant is not very googleable, a link would be nice.
Calvin Spealman said…
@YHVH Yes, port forwarding is managed by Vagrant and that is certainly one of the biggest boosts from it.

@Marius Thanks for pointing out my missing links. Fixed em'.
Calvin,

Thanks for the introduction to Vagrant. I've read your post and I've duly noted your documentation tips. I'll be sure to update the site with these changes before the next release.

And remember, I'm always in #vagrant (freenode IRC) if anyone needs any help.

Mitchell
Thank you for this helpful introduction. I didn't know about Vagrant before and I'm going to try it with Aeonic.

Popular posts from this blog

On Pruning Your Passions

We live in a hobby-rich world. There is no shortage of pastimes to grow a passion for. There is a shortage of one thing: time to indulge those passions. If you're someone who pours your heart into that one thing that makes your life worthwhile, that's a great deal. But, what if you've got no shortage of interests that draw your attention and you realize you will never have the time for all of them?

If I look at all the things I'd love to do with my life as a rose bush I'm tending, I realize that careful pruning is essential for the best outcome. This is a hard lesson to learn, because it can mean cutting beautiful flowers and watching the petals fall to the ground to wither. It has to be done.

I have a full time job that takes a lot of my mental energy. I have a wife and a son and family time is very important in my house. I try to read more, and I want to keep up with new developments in my career, and I'm trying to make time for simple, intentional relaxing t…

The Insidiousness of The Slow Solution

In software development, slow solutions can be worse than no progress at all. I'll even say its usually worse and if you find yourself making slow progress on a problem, consider stopping while you're a head.

Its easy to see why fast progress is better: either you solve the problem or you prove a proposed solution wrong and find a better one. Even a total standstill in pushing forward on a task or a bug or a request can force you to seek out new information or a second opinion.

Slow solutions, on the other hand, is kind of sneaky. Its insidious. Slow solution is related the Sunk Cost Fallacy, but maybe worse. Slow solutions have you constantly dripping more of your time, energy, and hope into a path that's still unproven, constantly digging a hole. Slow solutions are deceptive, because they still do offer real progress. It is hard to justify abandoning it or trying another route, because it is "working", technically.

We tend to romanticize the late night hacking…

Finding "One Game A Month"

I was really excited about the One Game A Month challenge as soon as I heard about it.
For about two years I've struggled in fits and starts to make my way into game development. This hasn't been productive in any of the ways I hoped when I started. Its really difficult to be fairly experienced as a developer, which I believe I am in my day job as a web developer, while struggling really hard at an area in which your experience just doesn't exist.
Its like being a pilot who doesn't know how to drive.

But this challenge provided a new breath to this little hobby of mine. It gave me a scaffolding to experiment, to learn, to reflect on finished projects. I had spent far too much time on game projects that stretched on far past their exciting phases, bogged down by bad decisions and regret.
And it has worked.
I have a lot to learn. I have a lot of experience to gain through trial and error and mistake and discovery. I have a lot of fun to be had making more small games t…