我尝试使用 Knife-solo 在 Vagrant 上安装 Ruby 2.0.0-p353。
当我以 root 和 vagrant 身份登录时,ruby -v
返回 Ruby 2.0.0-p353。
然而,当我跑步时bundle install
在Rails项目中,显示以下语句:
Your Ruby version is 1.8.7, but your Gemfile specified 2.0.0
Ruby的默认版本是1.8.7,所以我认为bundle install
指的是这个。
我应该怎么做才能解决这个问题?
$ 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 -)"
请执行以下步骤来解决该问题:
-
确保以下命令返回正确的 ruby 版本:
$ rbenv versions
system
2.0.0-p353
$ rbenv local
ruby-2.0.0
$ rbenv version
2.0.0-p353
-
确保获取的 ruby 版本正确:
$ bundle exec ruby -v
ruby 2.0.0-p353 (2013-11-22 revision 43784) [x86_64-linux]
-
如果您的 ruby 版本无效,您可以使用 shell 来验证问题是否存在bundler
通过致电:
$ bundle exec ruby -v
ruby 1.8.7
$ which bundle
/usr/bin/bundle
它说它将调用系统 ruby 来执行 ruby 脚本。
-
重新安装捆绑程序,然后确保当前的 ruby 有效:
$ gem install bundler
$ bundle exec ruby -v
ruby 2.0.0-p353 (2013-11-22 revision 43784) [x86_64-linux]
另请参阅如何正确设置 ruby 项目,该项目正在 rbenv/rvm 下开发here:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)