简体   繁体   English

Rails 3的“捆绑安装”速度超快(需要1秒),但之后没有Rails吗? (使用rvm)

[英]Rails 3's “bundle install” is super fast (takes 1 second), but no Rails is there afterwards? (using rvm)

I am using rvm, doing the following: 我正在使用rvm,执行以下操作:

rvm install ree    <--- (Ruby Enterprise Edition), or this can be 1.8.7 or 1.9.2
rvm ree
rvm gemset create 'proj'
cd path/to/proj
bundle install

so Gemfile in that project says: 所以该项目中的Gemfile说:

gem 'rails', '3.0.0'

and bundle install is super fast, reporting bundle install超快,报告

Using rails (3.0.0) 

but after that when I type 但在那之后我打字

$ rails -v
/Library/Ruby/Site/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
    from /Library/Ruby/Site/1.8/rubygems.rb:214:in `activate'
    from /Library/Ruby/Site/1.8/rubygems.rb:1082:in `gem'
    from /usr/bin/rails:18

$ which rails
/usr/bin/rails

so bundle install doesn't install the rails as a gem? 所以bundle install不会将rails作为gem安装? but if I type script/rails -v it shows it is 3.0.0 但如果我输入script/rails -v则表明它是3.0.0

This is correct. 这是对的。 bundle install won't install Rails as a gem in the conventional sense. bundle install不会像传统意义上那样将Rails安装为gem。 Now to explain why. 现在解释原因。

When Bundler runs an install, it will install the gems a directory: ~/.bundle/<type-of-ruby>/<version>/gems . 当Bundler运行安装时,它会在gems中安装一个目录: ~/.bundle/<type-of-ruby>/<version>/gems This is different to the normal way of installing them to a system path. 这与将它们安装到系统路径的常规方法不同。 When a gem is installed at a system path, the executable is made available because that directory is within the load path. 在系统路径上安装gem时,可执行文件可用,因为该目录位于加载路径中。 Now this is a bad thing, because you can only have one executable per gem . 现在这是一件坏事 ,因为每个gem只能有一个可执行文件。 Have you got SomeGem v2 installed but want to use the generator from SomeGem v1? 您是否安装了SomeGem v2但是想使用SomeGem v1中的生成器? Too bad. 太糟糕了。

Bundler solves this problem by installing them into the afore-mentioned location and only requiring specific versions of the gems it needs (specified inside of Gemfile . By running simply rails , you're trying to run the system executable (as in one provided by doing gem install rails ) rather than the Bundler one (provided by doing bundle install for a Rails project). Bundler通过将它们安装到上述位置并且只需要特定版本的Gemfile来解决这个问题(在Gemfile指定。通过简单地运行rails ,你试图运行系统可执行文件(如在gem install rails )而不是Bundler(通过为Rails项目进行bundle install提供)。

To run the one that Bundler installs you must run it like this bundle exec rails within a directory that contains a Gemfile that specifies any version of Rails. 要运行Bundler安装的那个,你必须在包含指定任何版本的Rails的Gemfile的目录中运行它,就像这个bundle exec rails一样。 Bundler will load a specific version of Rails and you should now be able to run them side-by-side with the only tradeoff being the bundle exec prefix to commands. Bundler将加载特定版本的Rails,你现在应该可以并排运行它们,唯一的权衡是bundle exec前缀命令。

Personally I've aliased this to be and two characters before some commands is a worthwhile tradeoff to avoiding The Seventh Circle of Gem Conflict Hell in my opinion. 就个人而言,我别名这be和之前的一些命令两个字符是一个值得权衡避免在我看来宝石冲突地狱的第七圈。

your procedure seems correct (be sure to use the newly created gemset too, verify by rvm info , do rvm ree@proj if it doesn't say gemset: 'proj' ), so I'll stick my head out and try a suggestion. 你的程序似乎是正确的(一定要使用新创建的gemset,请通过rvm info验证,如果它不说gemset:'proj',请执行rvm ree@proj ),所以我会坚持下去并尝试一个建议。 Btw, rails installs perfectly with bundler. 顺便说一句,rails与bundler完美安装。

I've been struggling with wierd behaviour system gems vs local gems, as have a lot of bundler users, including Yehuda Katz, leading to this comprehensive post A Tale of Abort Traps 我一直在与奇怪的行为系统宝石与本地宝石作斗争,因为有很多捆绑用户,包括Yehuda Katz,导致这个全面的帖子A Tale of Abort Traps

In short, if you run bundle install before you have the bundler gem (getting the "standard" gem not found error), then do gem install bundler , followed by another bundle install, the bundler gem has been install to your system, not rvm . 简而言之,如果你拥有bundler gem 之前运行bundle install(获得“标准”gem not found错误),那么执行gem install bundler ,然后再进行另一个bundle install,bundler gem已安装到你的系统,而不是rvm

Solution : Delete .bundle, (and do gem uninstall bundler?). 解决方案 :删除.bundle,(并执行gem uninstall bundler?)。 Then I would open a new term, do rvm ree@proj, and gem install bundler prior to bundle install. 然后我会在捆绑安装之前打开一个新术语,做rvm ree @ proj和gem install bundler。

Yehuda says in the post that it is fixed in new bundler versions, but I experienced this just a few days ago (bundler 1.0.0). Yehuda在帖子中说它已在新的捆绑版本中修复,但我几天前就遇到过这种情况(bundler 1.0.0)。 Hope I brought more help than confusion to the table :) 希望我带来更多的帮助而不是混乱到桌子上:)

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

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