What does bundle exec rake db:migrate
mean? Or just bundle exec rake <command>
in general?
I understand that bundle
takes care of maintaining things in the Gemfile. I know what the word "exec" means. I understand that rake
maintains all the different scripty things you can do, and I know that db:migrate
is one of those. I just don't know what all these words are doing together. Why should bundle
be used to execute rake
to execute a database migrate?
This comes up a lot when your gemfile.lock has different versions of the gems installed on your machine. You may get a warning after running rake (or rspec or others) such as:
You have already activated rake 10.3.1, but your Gemfile requires rake 10.1.0. Prepending "bundle exec" to your command may solve this.
Prepending
bundle exec
tells the bundler to execute this command regardless of the version differential. There isn't always an issue, however, you might run into problems.Fortunately, there is a gem that solves this: rubygems-bundler.
$ gem install rubygems-bundler
$ $ gem regenerate_binstubs
Then try your rake, rspec, or whatever again.