为什么在已经有rails 2.x的情况下,prawnto gem会安装rails 3.x? [英] Why prawnto gem installs rails 3.x when there is already a rails 2.x?
问题描述
我安装了 rails
(2.3.5)和 prawn
(0.12.0)。当我安装 prawnto
时,gem也会安装 rails
版本3.2.6。
prawnto 的依赖关系为:
prawn> = 0
rails> = 2.1
为什么当 prawnto
依赖关系已经存在时,gem会安装Rails 3.x? 使用Bundler。它很好。
好的,这基本上取决于RubyGems中依赖解析的工作原理。如果你对它不是很熟悉,那么赶快加快速度,就像使用XKCD漫画中的Primer面板一样快速。 RubyGems依赖管理和Primer故事情节在复杂性方面非常相似。当一个gem指定依赖关系时,比如 rails> = 2.1
,当您去安装该gem时,RubyGems会方便地忽略您目前安装的所有gem,然后查询web API以查找绝对最新版本的Rails,该版本大于或等于 2.1
。
在撰写本文时,它会发现版本 3.2.6
,因此会尽快安装该版本的Rails,因为它符合依赖性要求。它还会安装Rails的每一个依赖项,以及它们的依赖项和子子项子依赖项,直到没有安装依赖项的情况下没有gem。
我不会深入研究它的工作方式,因为这让我的视觉模糊不清。
现在,如果您使用的不是纯粹的东西 - 例如Bundler等RubyGems,您可以使用这样的Gemfile:
source'http://rubygems.org'
gem'rails','2.3.4'
gem'prawnto','0.1.1'
然后运行 这意味着如果你有 如果您有版本冲突,使用gem A指定对 我真的推荐使用Bundler来处理所有的Rails项目。即使那些在Rails 2上运行的应用程序。在Bundler网站上有一个页面,这将使您开始使用Rails 2.3项目和Bundler 。 I have The dependency of Why gem install Rails 3.x when the Alright, this is basically down to how dependency resolution works in RubyGems. If you're not terribly familiar with it, get up to speed real quick like with the Primer panel from this XKCD comic. RubyGems dependency management and the Primer storyline are very similar in terms of complexity. When a gem specifies a dependency of, say It will find, as of this writing, version I won't go into exactly how that works because it makes my vision go blurry when I think about it. Now, if you were using something that's not pure-RubyGems such as Bundler, you'd be able to have a Gemfile like this: And then run This means that if you have If you have conflicting versions, with a gem A specifying a dependency on gem B of I'd really recommend using Bundler for all your Rails projects. Even those that are running on Rails 2. There's a page on the Bundler website which will get you started with a Rails 2.3 project and Bundler. 这篇关于为什么在已经有rails 2.x的情况下,prawnto gem会安装rails 3.x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! bundle install
,然后执行 将会发生。 Bundler将找出 Gemfile
中指定的所有gem以及它们所依赖的gem的依赖关系,然后只安装那些gem。
prawnto
想要Rails > = 2.1
,它不会安装3.2.6,因为还有另一个依赖项,说明Rails 必须精确地 2.3.4
。因此,因此Rails 2.3.4将被安装。
〜> gt的gem B的依赖; 1.0
,但是然后gem C指定一个依赖关系,即gem B必须是'= 0.5.0',Bundler不会很高兴,并且会因为依赖关系无法解析而引发错误。 / p>
rails
(2.3.5) and prawn
(0.12.0) installed. When I install prawnto
, gem installs rails
version 3.2.6 also. prawnto
is:prawn >= 0
rails >= 2.1
prawnto
dependency is already there? tl;dr Use Bundler. It rocks.
rails >= 2.1
, when you go to install that gem, RubyGems conveniently ignores all the gems that you've currently got installed and then queries the web API to find the absolute latest version of Rails that's greater than or equal to 2.1
. 3.2.6
, and so will dutifully install that version of Rails because it fits the dependency requirements. It will also install every single dependency of Rails, and their dependencies, and the sub-sub-sub-sub-dependencies all the way down until there's not a gem left without a dependency installed.
source 'http://rubygems.org'
gem 'rails', '2.3.4'
gem 'prawnto', '0.1.1'
bundle install
and then something magical will happen. Bundler will figure out the dependencies for all the gems specified in the Gemfile
, as well as the gems that they depend on, and then install only those gems. prawnto
wanting Rails >= 2.1
, it won't install 3.2.6 because there's another dependency saying that Rails must precisely be 2.3.4
. So therefore Rails 2.3.4 will be installed.~> 1.0
, but then gem C specifying a dependency that gem B must be '= 0.5.0', Bundler won't be very happy and will raise an error because the dependencies can't be resolved.