“ bundle exec rake db:migrate”有什么作用? [英] what does it do by "bundle exec rake db:migrate"?

查看:154
本文介绍了“ bundle exec rake db:migrate”有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的研究,bundle exec负责在bundle的上下文中执行命令。

from my research, bundle exec is responsible for executing a command in the context of a bundle.

无论如何,我还不太了解它的作用对于命令 rake db:migrate bundle exec rake db:migrate 进行比较。

anyway, I don't quite understand yet for what it does differently for just the command rake db:migrate comparing with bundle exec rake db:migrate.

例如,在我的情况下,我执行了第一个命令,然后得到以下错误:

for example in my case, I executed the first command, and what I got was the following errors:

$ rake db:migrate
(in c:/rails/rails_projects/soccerweb)
rake aborted!
uninitialized constant Rake::DSL
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `requ
ire'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top
 (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `require'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `block in <class:TestUnitRailtie>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
block in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `b
lock in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `all'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `l
oad_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:103:
in `load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurabl
e.rb:30:in `method_missing'
c:/rails/rails_projects/soccerweb/Rakefile:7:in `<top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
c:/Ruby192/bin/rake:31:in `<main>'

但是当我在 rake db:migrate命令之前使用 bundle exec时,一切对我来说都很正常!

but when I used "bundle exec" preceding that "rake db:migrate" command, everything just worked for me gracefully!

任何人都可以阐明

推荐答案

bundle exec rake 运行的版本是 rake w在 Gemfile 中指定的副本。 rake 的默认版本(可以在 $ PATH 中找到的版本)可能与由捆绑执行耙子

bundle exec rake runs the version of rake which you've specified in your Gemfile. The default version of rake, the one which can be found in your $PATH, might be different than one executed by bundle exec rake.

您遇到的问题已在单独的问题。您的捆绑执行佣金最有可能在 $ PATH <中运行rake 0.8.7和 rake 。 / code>是受此问题影响的较新版本。

The problem you've experienced has been covered in a separate question. Your bundle exec rake most probably runs rake 0.8.7 and rake from your $PATH is a newer version which is affected by this problem.

man bundle exec


捆绑exec 对Shell环境进行了许多更改,然后完全执行您指定的命令。

bundle exec makes a number of changes to the shell environment, then executes the command you specify in full.


  • (...)

  • 将包含可执行文件(如rails,rspec,rackup)的目录放在$ PATH上

这篇关于“ bundle exec rake db:migrate”有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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