[英]Why is `bundle exec rails s` not the same as `rails s`?
尽管有这样的答案: rails s 或 bundle exec rails s
和这样的博客文章: https : //www.wyeworks.com/blog/2011/12/27/bundle-exec-rails-executes-bundler-setup-3-times/
这一切似乎都表明您应该简单地运行rails s
而不是bundle exec rails s
我仍然发现有时我不能简单地运行rails s
。 例如
$ rails s
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
而后立即在同一环境中运行:
$ bundle exec rails s
=> Booting WEBrick
=> Rails 4.0.0.beta1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2015-01-28 12:31:48] INFO WEBrick 1.3.1
[2015-01-28 12:31:48] INFO ruby 2.0.0 (2014-11-13) [x86_64-darwin14.0.0]
[2015-01-28 12:31:48] INFO WEBrick::HTTPServer#start: pid=18959 port=3000
为什么不一样? 这种行为是否应该修复,如果是,如何修复?
==== 更新
回应@awendt
$ which rails
/Users/snowcrash/.rvm/gems/ruby-2.0.0-p598/bin/rails
$ rails c
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
$ bundle exec rails c
Loading development environment (Rails 4.0.0.beta1)
2.0.0-p598 :001 >
试图重现这一点,我得到(在 Ubuntu 12.04.5 LTS 上):
me@machine:/some/path$ rails c
The program 'rails' is currently not installed. To run 'rails' please ask your administrator to install the package 'rails'
me@machine:/some/path$ which rails
me@machine:/some/path$
所以就我而言, rails 脚本不在我的$PATH
。
您的设置有所不同,因为该消息明确提到了 gems。 你甚至可能会得到这个:
you@machine:/some/path$ which rails
/usr/bin/rails
you@machine:/some/path$
因为/usr/bin/
在其他事情之前的某个地方位于您的$PATH
,并且您仍在调用 OS 附带的 rails 脚本。
无论如何,重要的部分是: bundle exec rails c
让 Bundler 找出在哪里可以找到 Rails gem,而不是让 shell 找出来。
您可以将 gem 安装到一个完全任意的位置,只有 Bundler 可以在其中找到它们,因为该位置不在您的$PATH
而是在您的$BUNDLE_PATH
(请参阅bundle config
的可用密钥列表)。
这就是rails
和bundle exec rails
不一样的原因。
这不是错误,不应修复该行为。 是的,您不必运行bundle exec rails
因为在最近的版本中, rails
做完全相同的事情。 但是您看到的错误是一个不同的问题。
对于Rails 3x
及更高版本,无论何时运行rails server
,它始终处于您的environment
和Gemfile
上下文中。因此, bundler
有助于在这方面使用$BUNDLE_PATH
启动和加载所需的gems/libraries 以启动应用程序,该应用程序通过如果你不使用默认的不会是有bundle exec
取而代之的则仅包括默认库/使用宝石gemset
(如果你使用rvm
)或默认路径负载。
..希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.