【问题标题】:Why "bundle install" try to install outdated version of gems?为什么“捆绑安装”尝试安装过时的 gems 版本?
【发布时间】:2013-08-12 19:14:43
【问题描述】:

我有不同的宝石组

> rvm gemset list
gemsets for ruby-2.0.0-p247 (found in /Users/kai/.rvm/gems/ruby-2.0.0-p247)
=> (default)
   global
   rails4

> rvm gemset use rails4
Using ruby-2.0.0-p247 with gemset rails4

> rails -v
/Users/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'railties' (>= 0) among 43 total gem(s) (Gem::LoadError)
    from /Users/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /Users/kai/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /usr/bin/rails:22:in `<main>'
    from /Users/kai/.rvm/gems/ruby-2.0.0-p247@rails4/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/kai/.rvm/gems/ruby-2.0.0-p247@rails4/bin/ruby_noexec_wrapper:14:in `<main>'

当我在做的时候:

> bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.1.0) 
Installing i18n (0.6.4) 
Installing multi_json (1.7.9) 
Installing activesupport (3.2.7) 
Installing builder (3.0.4) 
Installing activemodel (3.2.7) 
Installing erubis (2.7.0) 
Installing journey (1.0.4) 
Installing rack (1.4.5) 
Installing rack-cache (1.2) 
Installing rack-test (0.6.2) 
Installing hike (1.2.3) 
Installing tilt (1.4.1) 
Installing sprockets (2.1.3) 
Installing actionpack (3.2.7) 
Installing mime-types (1.23) 
Installing polyglot (0.3.3) 
Installing treetop (1.4.14) 
Installing mail (2.4.4) 
Installing actionmailer (3.2.7) 
Installing arel (3.0.2) 
Installing tzinfo (0.3.37) 
Installing activerecord (3.2.7) 
Installing activeresource (3.2.7) 
Installing coffee-script-source (1.6.3) 
Installing execjs (1.4.0) 
Installing coffee-script (2.2.0) 
Installing rack-ssl (1.3.3) 
Installing json (1.8.0) 
Installing rdoc (3.12.2) 
Installing thor (0.18.1) 
Installing railties (3.2.7) 
Installing coffee-rails (3.2.2) 
Installing jquery-rails (3.0.4) 
Using bundler (1.3.5) 
Installing rails (3.2.7) 
Installing sass (3.2.10) 
Installing sass-rails (3.2.6) 
Installing sqlite3 (1.3.7) 
Installing uglifier (2.1.2) 
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

但我有 ruby​​ 2.0!为什么不安装 rails 4.0 和 activesupport 4.0?

【问题讨论】:

  • 我们可以看看你的 Gemfile 吗?
  • 听起来你的 gemfile 中没有编写 Rails

标签: ruby-on-rails ruby gem rvm bundle


【解决方案1】:

bundler基于两个文件安装gem:

  1. Gemfile.lock以前安装时保存的严格版本,
  2. Gemfile 来自用户的宽松版本声明。

当您首先生成rails 项目时,Gemfile 是这样生成的:

gem 'rails', '~> 3.2'

在生成bundle install 文件后,运行会生成Gemfile.lock,其中记录了严格版本的gem,从现在开始,对bundle install 的任何后续调用都将仅安装保存在Gemfile.lock 中的版本。

要将 gem 更新到较新的版本:

  1. 检查 Gemfile 是否有任何版本限制 - 这可能会阻止安装您想要的版本
  2. 运行 bundle update &lt;gem_name&gt; 仅更新这个单一的 gem 以及它的要求 - 但将更改的范围最小化为​​尽可能小的更改集。
  3. 运行bundle update 将所有gem 更新到Gemfile 中允许的最新版本

【讨论】:

    【解决方案2】:

    bundle install 或简而言之 bundle 不会安装最新的 gem,除非您在 Gemfile 中遗漏了版本。例如

    gem 'rails'
    

    但通常情况并非如此,我们指定版本以防止应用程序在更新某些 gem 时“崩溃”并且我们在不知不觉中运行 bundle update,或者就此将应用程序移动到测试或生产服务器。通常在向 Gemfile 添加 gem 时,我们会这样做:

    gem 'rails', '~> 3.2.7'
    

    注意版本号中的前导~&gt;。这说:在版本3.2.7 和小于3.3.0 之间使用rails gem。

    为了让您的 bundle 命令获取 rails 4.0,您需要更改该行以读取以下任一内容:

    gem 'rails', '>= 3.2.7' 
    

    gem 'rails', '4.0.0'
    

    如果您使用gem 'rails', '&gt;= 3.2.7',那么您的 Rails 应用程序将使用系统中可用的最新 gem。请注意,3.2.7 只是我在这里使用的一个示例。如果您使用gem 'rails', '4.0.0',那么您的rails 应用程序将使用rails 版本4.0.0。

    请注意,此更改可能会破坏您现有的 rails 3.2 应用程序。

    【讨论】:

      猜你喜欢
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2021-05-25
      • 1970-01-01
      • 2012-01-18
      • 1970-01-01
      相关资源
      最近更新 更多