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 -)"
Please do the following steps to fix the problem:
Make sure that the following commands returns the proper version of ruby:
$ rbenv versions
system
2.0.0-p353
$ rbenv local
ruby-2.0.0
$ rbenv version
2.0.0-p353
Make sure that getting the version of ruby is correct:
$ bundle exec ruby -v
ruby 2.0.0-p353 (2013-11-22 revision 43784) [x86_64-linux]
If you got invalid version of ruby, you shell to verify that problem is in bundler
by calling:
$ bundle exec ruby -v
ruby 1.8.7
$ which bundle
/usr/bin/bundle
It says that it will call system ruby to proceed ruby scripts.
Reinstall bundler, and then make sure that now current ruby is valid:
$ gem install bundler
$ bundle exec ruby -v
ruby 2.0.0-p353 (2013-11-22 revision 43784) [x86_64-linux]
Also refer to how to properly set up a ruby project, which is being developed under rbenv/rvm here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With