Last Updated: February 25, 2016
· tcnksm

Prepare VM installed multiple versions of ruby by Vagrant and chef

In case building ruby program, sometimes we need test environment which is installed multiple versions of ruby. In this case, Vagrant is nice to use. But install ruby by hand is very annoy and waste of time. Using chef for installing rubies, is easy and I can administrate it by github and so on. So I created minimum set of this, creating tcnksm/vagrant-chef-ruby.


First, I set up vagrant. In this case, I used Ubuntu Precise 12.04 (64 bit). Prepare it by below;

vagrant init precise64 http://files.vagrantup.com/precise64.box

When we use chef with vagrant, vagrant-omunibus is useful. It installs chef automatically if chef is not installed in VM when vagrant up. Install it by vagrant plugin install vagrant-omnibus and add its setting to Vagrantfile like below;

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
     # vagrant-omnibus (setup chef-environment in vm)
     config.omnibus.chef_version = "11.4.0"

After adding, start up VM with vagrant up.


To apply chef, I use knife-solo.

I've created cookbook for installing multiple versions of ruby by rbenv because I can use it another project like (tcnksm/chef-dev-env)[https://github.com/tcnksm/chef-dev-env]. Its repository is here.

This cookbook does the same as when we install multiple versions of ruby by rbenv.

  1. Prepare packages like libyaml-dev or libxml2-dev for building ruby
  2. Clone rbenv from github
  3. Clone ruby-build from github
  4. Install ruby with rbenv install ...

node file for this is like below;

        "name": "vagrant",
        "home": "/home/vagrant",
        "group": "vagrant"



For install this cookbook, I use Berkshelf. Add setting to Berksfile like below and execute berks install --path cookbooks.

cookbook 'rubies', :git => 'https://github.com/tcnksm/chef-rubies'

After that excuting knife-solo.

knife solo cook -c config/solo.rb [vagrant-hostname]

From now, I can prepare environment for testing multiple versions of ruby more easily .

Say Thanks
Awesome Job

B6c77ad0 c95b 11e7 8263 8f89080b8db6
Ruby Developer Backend
Austria (Vienna or Linz)
Full Time