Rails 3的“捆绑安装”超快(需要1秒),但是之后没有Rails? (使用rvm) [英] Rails 3's "bundle install" is super fast (takes 1 second), but no Rails is there afterwards? (using rvm)

查看:97
本文介绍了Rails 3的“捆绑安装”超快(需要1秒),但是之后没有Rails? (使用rvm)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用rvm,执行以下操作:

  rvm install ree <---(Ruby Enterprise Edition),或者这可以是1.8.7或1.9.2 
rvm ree
rvm gemset create'proj'
cd path / to / proj
bundle install

因此该项目中的Gemfile说:

  gem'rails','3.0.0'

使用rails(3.0.0)

安装 code> 

但之后当我输入

  $ rails -v 
/Library/Ruby/Site/1.8/rubygems.rb:779:in`report_activate_error':找不到RubyGem rails(> = 0)(Gem :: LoadError)$ b $ / 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
/ usr / bin / rails

so bundle install code>不会将rails安装为gem?
,但是如果我键入 script / rails -v ,它会显示它是3.0.0

解决方案

这是正确的。 bundle install 不会将Rails安装为传统意义上的宝石。现在解释原因。



当Bundler运行安装时,它会将gems安装到一个目录中:〜/ .bundle /< type-of -ruby> /<版本> /宝石。这与将它们安装到系统路径的正常方式不同。当gem安装在系统路径中时,由于该目录位于加载路径中,因此可执行文件变得可用。现在,这是一个错误的事情,因为每个宝石只能有一个可执行文件 。你是否安装了SomeGem v2,但想使用SomeGem v1中的生成器?太糟糕了。

Bundler通过将它们安装到上述位置解决了这个问题,并且只需要特定版本的宝石(在 Gemfile 。通过简单地运行 rails ,你试图运行 system 可执行文件做 gem install rails )而不是Bundler的一个(通过为Rails项目执行 bundle install 提供) p>

要运行Bundler安装的那个,您必须在包含<$的目录内运行它,如 bundle exec rails c $ c> Gemfile 指定任何版本的Rails Bundler将加载特定版本的Rails,现在你应该能够并行运行它们,唯一的折衷是 bundle exec 前缀到命令。



就我个人而言,我已经将它命名为 be

I am using rvm, doing the following:

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:

gem 'rails', '3.0.0'

and bundle install is super fast, reporting

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? but if I type script/rails -v it shows it is 3.0.0

解决方案

This is correct. bundle install won't install Rails as a gem in the conventional sense. Now to explain why.

When Bundler runs an install, it will install the gems a directory: ~/.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. Now this is a bad thing, because you can only have one executable per gem. Have you got SomeGem v2 installed but want to use the generator from 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).

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

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.

这篇关于Rails 3的“捆绑安装”超快(需要1秒),但是之后没有Rails? (使用rvm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆