“ rails s”和“ rails s”之间有什么区别?和“ bundle exec rails”? [英] What is the difference between "rails s" and "bundle exec rails s"?

查看:149
本文介绍了“ rails s”和“ rails s”之间有什么区别?和“ bundle exec rails”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rails s bundle exec rails 有什么区别?人们似乎在说 bundle exec rails c更好,但是为什么呢?同时这篇文章 rails s 更好。

What is the difference between rails s and bundle exec rails s? People seem to say that bundle exec rails s is better, but why? Meanwhile this post says rails s is better.

这是哪个?

推荐答案

有时,当您安装gem时,它也附带可执行文件/二进制文件。这些示例包括: rails rake rspec pry 等。但是,当您有多个版本时安装了gem之后,您将拥有这些可执行文件的多个版本。因此,如果要为给定的Rails应用执行这些二进制文件之一,则可能需要消除所需的可执行文件的歧义-例如,一个用于rake v10.1的可执行文件或一个用于rake v10.2的可执行文件。由于可以通过Gemfile.lock文件中的gem版本(由bundler创建)找到答案,因此bundler提供了一个命令,用于根据当前项目的Gemfile中指定的版本执行二进制文件。锁。该命令是 bundle exec< command>

Sometimes when you install a gem it comes with an executable/binary as well. Examples of these include: rails, rake, rspec, pry, etc. However, when you have multiple versions of a gem installed you then will have multiple versions of these executables sitting around. So if you want to execute one of these binaries for a given rails app you may need to disambiguate which executable you want -- the one for rake v10.1 or the one for rake v10.2, for example. Since the answer to this is discoverable by the version of the gem you have in your Gemfile.lock file (which is created by bundler), bundler supplies a command for executing a binary based on the version that is specified in the current project's Gemfile.lock. This command is bundle exec <command>.

因此,对于大多数命令,您都需要运行 bundle exec< command> ,以确保您正在为项目运行正确的版本(并确保还从Gemfile中指定的正确版本中加载了所有依赖项) 。锁)。该规则的一个臭名昭著的例外是 rails 命令。原因是 rails 命令要做的第一件事是加载捆绑程序并检查要执行的命令版本。因此,在运行 rails 命令时,您实际上只是放慢了自己对捆绑程序的投入。

So for most commands you'll want to run bundle exec <command> to make sure you're running the right version for your project (and also to make sure that all dependencies are also loaded from the correct versions specified in your Gemfile.lock). The one notorious exception to this rule is the rails command. The reason being that the first thing the rails command does is load up bundler and check which version of the command to execute. So you'd really just be slowing yourself down to involve bundler in the first place when running the rails command.

因此,简而言之,使用:

So, in short, use:

rails server
rails console
bundle exec <some command that isn't rails>

这篇关于“ rails s”和“ rails s”之间有什么区别?和“ bundle exec rails”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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