Bundle安装是否使用不同的Ruby版本?

Bundle安装是否使用不同的Ruby版本?,ruby,chef-infra,vagrant,rbenv,Ruby,Chef Infra,Vagrant,Rbenv,我尝试使用刀子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 si

我尝试使用刀子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版本无效,您可以通过调用以下命令来验证问题是否存在于
    bundler

    $ bundle exec ruby -v
    ruby 1.8.7
    
    $ which bundle
    /usr/bin/bundle
    
    它说它将调用SystemRuby来执行ruby脚本

  • 重新安装bundler,然后确保当前ruby有效:

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

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

    如果您使用了
    rbenv
    ,请从这里尝试我的答案:谢谢您的回答。我试着按照那一页去做,但做不到。例如,
    bundle install
    返回
    Gem::InstallError:activesupport需要Ruby版本>=1.9.3.
    。但是您的Ruby版本>=1.9.3,您的版本是2.0.0吗?或者1.8.7?
    ruby-v
    返回
    ruby 2.0.0p353(2013-11-22修订版43784)[x86\u 64-linux]
    ,所以我认为它应该能够毫无问题地运行?