Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'bundle exec rake' versus rake do?

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?

like image 474
Blankman Avatar asked Dec 24 '12 21:12

Blankman


People also ask

What is bundle exec rake db migrate?

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.

What does bundle exec rake do?

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.

Is bundle exec necessary?

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.


2 Answers

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

like image 176
Anatoliy Kukul Avatar answered Oct 12 '22 20:10

Anatoliy Kukul


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.

like image 22
weddingcakes Avatar answered Oct 12 '22 21:10

weddingcakes