简体   繁体   English

在Ruby on Rails中使用bundle exec

[英]use of bundle exec in Ruby on Rails

What does bundle exec rake db:migrate really means? bundle exec rake db:migrate真的意味着什么? or bundle exec rails s I understand that bundle handle all the gems we specify in our Gemfile,and rake handle all the things which you can do through scripts but these commands don't get executed without prefixing bundle exec and I couldn't find any documentation about this on internet !! 或捆绑exec rails我理解bundle处理我们在Gemfile中指定的所有gem,并且rake处理你可以通过脚本完成的所有事情,但这些命令没有在没有前缀bundle exec的情况下执行,我找不到任何东西关于这个在互联网上的文档

Bundler - The best way to manage your application's dependencies Bundler - 管理应用程序依赖关系的最佳方式

Run the command in context of the bundle 在捆绑包的上下文中运行命令

$ bundle exec $ bundle exec

Exec runs a command, providing it access to the gems in the bundle. Exec运行一个命令,使其可以访问bundle中的gem。 While using bundle exec you can require and call the bundled gems as if they were installed into the systemwide RubyGems repository 使用bundle exec时,您可以要求并调用捆​​绑的gem,就好像它们被安装到系统范围的RubyGems存储库中一样

With: 附:

bundle exec rake db:migrate bundle exec rake db:migrate

In an informal way, it means that your rails environment will 以非正式的方式,这意味着您的rails环境将会

-Install dependencies with bundler then -Run your database migrations in your rails app (/yourapp/db/migrate) - 然后使用bundler安装依赖项 - 在rails app中运行数据库迁移(/ yourapp / db / migrate)

Instead of a database operation, you could do any other command line stuff that can be controlled by rake (like building your app, extensions, cleaning some files, etc.) 您可以执行任何其他可由rake控制的命令行内容(例如构建应用程序,扩展程序,清理某些文件等),而不是数据库操作。

This can be useful if you want to avoid confusing scenarios where maybe some gems in your setup are outdated, or missing from your environment. 如果您想避免令人困惑的场景,这可能会很有用,因为您的设置中的某些宝石可能已过时,或者您的环境中缺少这些宝石。 It's a good practice because calling rake by itself will not guarantee that you got all your dependencies in check. 这是一个很好的做法,因为单独调用rake并不能保证你能检查所有的依赖项。

Bundler acts to create a somewhat isolated Ruby language programming environment separate from the underlying host system. Bundler用于创建与底层主机系统分离的有些独立的Ruby语言编程环境。 There are limits to what it can do. 它能做什么是有限的。 For example, you need something like RVM to manage different versions of the Ruby language virtual machine. 例如,您需要像RVM这样的东西来管理不同版本的Ruby语言虚拟机。 And of course both Ruby and Bundler itself have to be available outside your project in order to run. 当然,Ruby和Bundler本身都必须在项目之外可用才能运行。

However, within a single project bundle exec will restrict access to gems installed by Bundler into that project. 但是,在单个项目bundle exec将限制对Bundler安装到该项目中的gem的访问。 This means that the Rake utility when invoked via bundle exec will be the version of rake installed in your project and not the system-wide version. 这意味着通过bundle exec调用的Rake实用程序将是项目中安装的rake版本,而不是系统范围的版本。 It also means that `bundle rake db:migrate' will use the correct version of rails installed for your project. 这也意味着`bundle rake db:migrate'将使用为您的项目安装的正确版本的rails。 This isolates your project from updates done to the Ruby environment on the host and thereby prevents compatibility issues from arising. 这会将您的项目与主机上对Ruby环境所做的更新隔离开来,从而防止出现兼容性问题。

You can get around the verbosity by creating aliases in your .bash_profile (assuming you are using OSX or Linux/unix) for bundle exec , bundle exec rake and bundle exec rails . 您可以通过在.bash_profile中创建别名(假设您使用的是OSX或Linux / unix)来为bundle execbundle exec rakebundle exec rails创建别名。 I use bexec, brake and brails. 我使用bexec,刹车和辫子。

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

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