加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Bundle install是使用不同的Ruby版本吗?

发布时间:2020-12-17 02:21:48 所属栏目:百科 来源:网络整理
导读:我尝试使用knife-solo在Vagrant上安装 Ruby 2.0.0-p353. 当我以root和vagrant身份登录时,ruby -v返回Ruby 2.0.0-p353. 但是,当我在Rails项目中运行bundle install时,将显示以下语句: Your Ruby version is 1.8.7,but your Gemfile specified 2.0.0 Ruby的默
我尝试使用knife-solo在Vagrant上安装 Ruby 2.0.0-p353.
当我以root和vagrant身份登录时,ruby -v返回Ruby 2.0.0-p353.

但是,当我在Rails项目中运行bundle install时,将显示以下语句:

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来验证问题是否在bundle中:

$bundle exec ruby -v
ruby 1.8.7

$which bundle
/usr/bin/bundle

它说它将调用系统ruby来继续ruby脚本.
>重新安装bundler,然后确保现在的ruby有效:

$gem install bundler

$bundle exec ruby -v
ruby 2.0.0-p353 (2013-11-22 revision 43784) [x86_64-linux]

另请参阅如何正确设置正在rbenv / rvm here下开发的ruby项目:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读