Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Vagrant: EC2-Like Virtual Machine Building and Provisioning from Ruby

By Peter Cooper / March 8, 2010

vagrant_chilling.pngVagrant is a Ruby-based tool for building and deploying virtualized development environments. It uses Oracle's open-source VirtualBox virtualization system along with the Chef configuration management engine along with lots of Ruby goodness to automate the creation and provisioning of virtual machines for development purposes.

If you thought rolling out new VMs using Amazon EC2 was easy, Vagrant brings an even simpler system to your local development machine. From the command line, starting is as easy as:

sudo gem install vagrant
vagrant box add base
mkdir vagrant
vagrant init
vagrant up

Be warned, though - as a 370MB download, adding that box image isn't a quick process! Once you've got it though, you can keep rolling out VMs based on it at will.

Note that VirtualBox is a separate dependency for Vagrant. Vagrant does not come with VirtualBox built in or anything like that. Download VirtualBox for your OS if you want to try Vagrant.

Beyond the basics of getting a VM running, Vagrant can take care of port forwarding, distribution, environment setup, SSH access, shared folders and, importantly, the provisioning of software onto the VM using Chef. If you want to automatically roll out a VM with Apache 2, Rails, Phusion Passenger, or the like, Chef and Vagrant will take care of it for you. This is powerful stuff!

In terms of documentation and having a straight forward official homepage, Vagrant sets a solid benchmark. There's a straightforward guide to getting started with Vagrant, lots of documentation, and a 12 minute getting started video/screencast. Great work guys!


  1. Peter Cooper says:

    Serves me right for finishing the post while downloading that box image.. when I did vagrant up, I get an error message *groan*:

    [22:59:17 ~]$ vagrant up
    [INFO 03-08-2010 22:59:21] Vagrant: Reloading configuration to account for loaded box...
    /Library/Ruby/Gems/1.8/gems/vagrant-0.1.1/bin/../lib/../lib/vagrant/env.rb:75:in `read': Is a directory - /Users/peter/.vagrant (Errno::EISDIR)

    If I get it sorted out, I'll post again. This is on OS X 10.6..

  2. Peter Cooper says:

    Digging deeper into the instructions seems to show that making a separate folder then running vagrant init is better. I tried that and got a totally different exception:

    [23:02:32 ~/Sandbox/v]$ vagrant up
    [INFO 03-08-2010 23:02:35] Vagrant: Reloading configuration to account for loaded box...
    [INFO 03-08-2010 23:02:35] Vagrant: Importing base VM (/Users/peter/.vagrant/boxes/base/box.ovf)...
    /Library/Ruby/Gems/1.8/gems/vagrant-0.1.1/bin/../lib/../lib/vagrant/env.rb:74: command not found: VBoxManage -q import /Users/peter/.vagrant/boxes/base/box.ovf
  3. Peter Cooper says:

    Suspecting this isn't as clever as I thought it was and that I actually need to install VirtualBox separately first ;-) Giving that a go.

  4. Peter Cooper says:

    Aha, that's a bingo! Updating post..

  5. Peter Cooper says:

    All working now and post has been updated with further instructions. Still having issues rolling out multiple VMs at a time though, but investigating that further.. will post anything useful I get.

  6. Peter Cooper says:

    OK. If you want multiple VMs for now, create multiple directories, do vagrant init in each, then add a config setting to each Vagrantfile forwarding a different port to each for SSH (or other) purposes, e.g:

    config.vm.forward_port("ssh", 22, 10001)

    And on another..

    config.vm.forward_port("ssh", 22, 10002)

    And so forth.

  7. Mitchell Hashimoto says:


    Thanks for the article! Quick, too!

    Sorry about the trouble you had getting multiple VMs up at the same time. Multiple VMs within a single project is something I'd like to do in the future so Vagrant can be used to model more complex web applications more accurately (such as load balancers, separate utility servers, and so on), but its something which was just too complicated to get out with an initial release.

    It seems that John helped you get it all working. Fantastic.

    Thanks again!

Other Posts to Enjoy

Twitter Mentions