简体   繁体   English

为什么“捆绑安装”尝试安装过时版本的宝石?

[英]Why “bundle install” try to install outdated version of gems?

I have different gemsets 我有不同的宝石

> 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>'

and when I'm doing: 当我在做的时候:

> 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!

But I have ruby 2.0! 但我有红宝石2.0! Why it doesn't install rails 4.0 and activesupport 4.0? 为什么它不安装rails 4.0和activesupport 4.0?

bundler installs gems basing on two files: bundler基于两个文件安装gem:

  1. Gemfile.lock strict versions saved during previous installation, 在以前的安装过程中保存的Gemfile.lock严格版本,
  2. Gemfile loose version declaration from user. 用户的Gemfile松散版声明。

when you generate rails project first Gemfile is generated with something like this: 当你生成rails项目时,首先生成Gemfile ,如下所示:

gem 'rails', '~> 3.2'

after the file is generated bundle install is ran which generates Gemfile.lock in which strict versions of gems are recorded, from now on any succeeding call to bundle install will install only the versions saved in Gemfile.lock . 生成文件后运行bundle install ,生成Gemfile.lock ,其中记录了严格版本的gem,从现在开始,对bundle install任何后续调用都只会安装Gemfile.lock保存的版本。

To update gems to newer versions: 要将Gems更新为更新版本:

  1. check Gemfile for any version restrictions - that might prevent installing the versions you would like to get 检查Gemfile是否有任何版本限制 - 这可能会阻止安装您想要的版本
  2. run bundle update <gem_name> to update only this single gem and what is require for it - but minimalizing scope of the changes to the smallest possible set of changes. 运行bundle update <gem_name>只更新这个gem以及它需要什么 - 但是将更改的范围最小化到尽可能小的更改集。
  3. run bundle update to update all gems to latest versions allowed in Gemfile 运行bundle update以将所有gem bundle updateGemfile允许的最新版本

bundle install or in short bundle does not install the latest gem unless you have left out the version in your Gemfile. bundle install或者short bundle不会安装最新的gem,除非你遗漏了Gemfile中的版本。 eg 例如

gem 'rails'

But usually this is not the case, we specify versions to prevent application from "crashing" when some gems are updated and we unknowingly run bundle update , or for that matter move application to say test or production servers. 但通常情况并非如此,我们指定版本以防止应用程序在某些宝石更新时“崩溃”并且我们无意中运行bundle update ,或者就此而言移动应用程序来说测试或生产服务器。 Usually when adding a gem to Gemfile, we do: 通常在向Gemfile添加gem时,我们会:

gem 'rails', '~> 3.2.7'

Note the leading ~> in the version number. 请注意版本号中的前导~> This says: use rails gem between versions 3.2.7 and less than 3.3.0 . 这表示:在版本3.2.7和小于3.3.0之间使用rails gem。

In order for your bundle command to grab rails 4.0, you need to change that line to read either one of the following: 为了使您的bundle命令能够获取rails 4.0,您需要更改该行以读取以下任一项:

gem 'rails', '>= 3.2.7' 

or 要么

gem 'rails', '4.0.0'

If you use gem 'rails', '>= 3.2.7' then your rails application will use the latest gem available in your system. 如果您使用gem 'rails', '>= 3.2.7'那么您的rails应用程序将使用您系统中可用的最新gem。 Note that 3.2.7 is just an example I'm using here. 请注意, 3.2.7只是我在这里使用的一个例子。 If you use gem 'rails', '4.0.0' then your rails application will use rails version 4.0.0. 如果您使用gem 'rails', '4.0.0'那么您的rails应用程序将使用rails版本4.0.0。

Please note that this change might break your existing rails 3.2 application. 请注意,此更改可能会破坏您现有的rails 3.2应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM