Bundle install is using a different Ruby version?

Viewed 9170

I tried to install Ruby 2.0.0-p353 on Vagrant using knife-solo. When I logged in as root and vagrant, ruby -v returns Ruby 2.0.0-p353.

However, when I run bundle install in a Rails project, the following statement is displayed:

Your Ruby version is 1.8.7, but your Gemfile specified 2.0.0

The default version of Ruby is 1.8.7, so I think bundle install is referring to this. What should I do to solve this problem?

$ cat site-cookbooks/ruby/recipes/default.rb

group 'rbenv' do
  action :create
  members 'vagrant'
  append true
end

git '/usr/local/rbenv' do
  repository 'git://github.com/sstephenson/rbenv.git'
  reference 'master'
  action :checkout
  user "#{node.user}"
  group 'rbenv'
end

directory '/usr/local/rbenv/plugins' do
  owner "#{node.user}"
  group 'rbenv'
  mode 0755
  action :create
end

template '/etc/profile.d/rbenv.sh' do
  owner "#{node.user}"
  group "#{node.user}"
  mode 0644
end

git '/usr/local/rbenv/plugins/ruby-build' do
  repository 'git://github.com/sstephenson/ruby-build.git'
  reference 'master'
  action :checkout
  user "#{node.user}"
  group 'rbenv'
end

execute 'ruby install' do
  not_if "source /etc/profile.d/rbenv.sh; rbenv versions | grep #{node.ruby.version}"
  command "source /etc/profile.d/rbenv.sh; rbenv install #{node.ruby.version}"
  action :run
end

execute 'ruby change' do
  command "source /etc/profile.d/rbenv.sh; rbenv global #{node.ruby.version}; rbenv rehash"
  action :run
end

$ cat site-cookbooks/ruby/attributes/default.rb

default['user'] = 'root'
default['ruby']['version'] = '2.0.0-p353'

$ cat site-cookbooks/ruby/templates/default/rbenv.sh.rb

export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
1 Answers
Related