What is the difference between doing:
bundle exec rake
and
rake
I see people doing both, I never do bundle
before my commands, curious what the reason for it is?
bundle exec is a Bundler command to execute a script in the context of the current bundle (the one from your directory's Gemfile). rake db:migrate is the script where db is the namespace and migrate is the task name defined.
bundle exec allows us to run an executable script in the specific context of the project's bundle. Upon running the above command, bundle exec will run the executable script for rake version specified in project's Gemfile thus avoiding any conflicts with other versions of rake installed system-wide.
If you get tired of typing bundle exec all the time, you can configure rvm so it's not necessary: ruby.railstutorial.org/chapters/… A nice side-effect of using bundle exec is that it will also tell you if you should run bundle install to install versions of gems you are missing compared to the Gemfile. lock file.
bundle exec
executes a command in the context of the bundle. This command executes the command, making all gems specified in the Gemfile
available to require in Ruby programs. Very useful when you have many applications with different versions of gems used in them.
Please see docs for more information: http://gembundler.com/man/bundle-exec.1.html
bundle exec
runs the command after it in the environment of Bundler. So say you had rake 0.9 in you Gemfile, but rake 10 installed in RubyGems.bundle exec rake
will run rake 0.9 instead of rake 10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With