Rbenv vagrant global ruby version unchanged

1.9k views Asked by At

I am using Vagrant with Berkshelf plugin to create an Ubuntu 12.04 machine with Ruby 2.0.0-p247 as the default. When the machine loads, ruby -v returns ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux], indicating that rbenv has not installed the correct version.

Also, if I try rbenv global 2.0.0-p247 I receive the error rbenv: version2.0.0-p247' not installed`

Any ideas what I'm doing wrong?

Thanks

Vagrantfile:

config.berkshelf.enabled = true

config.omnibus.chef_version = :latest

config.vm.provision :shell, :inline => "gem install chef --no-rdoc --no-ri --conservative"

config.vm.provision :chef_solo do |chef|
chef.add_recipe "apt"
chef.add_recipe "git"
chef.add_recipe "build-essential"
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "rbenv::system"

chef.json = {
  'rbenv' => {
    'user_installs' => [
      {
        'user'    => 'vagrant',
        'rubies'  => ['2.0.0-p247'],
        'global'  => '2.0.0-p247',
        'gems'    => {
          '2.0.0-p247' => [
            { 'name'    => 'bundler' },
            { 'name'    => 'rake' }
          ]
        }
      }
    ]
    }
  }
end

Berksfile:

site :opscode

cookbook 'apt'
cookbook 'git'
cookbook 'build-essential'
cookbook 'ruby_build'
cookbook 'rbenv', git: 'git://github.com/fnichol/chef-rbenv.git', ref: "v0.7.2"
1

There are 1 answers

0
cassianoleal On BEST ANSWER

You're installing user Rubies with the rbenv cookbook. In your case, the rbenv::system recipe is doing nothing, since you didn't specify any system Ruby to install.

Instead, include the rbenv::user recipe:

...
chef.add_recipe "ruby_build"
chef.add_recipe "rbenv::vagrant"
chef.add_recipe "rbenv::user"     ### This is the recipe you want

chef.json = {
  'rbenv' => {
    'user_installs' => [
      {
        'user'    => 'vagrant',
        'rubies'  => ['2.0.0-p247'],
...