Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between rake and bin/rake

Can someone explain the differences between the following commands?

rake assets:precompile

bin/rake assets:precompile

RAILS_ENV=production rake assets:precompile

RAILS_ENV=production bin/rake assets:precompile

like image 551
ahnbizcad Avatar asked Aug 23 '26 18:08

ahnbizcad


1 Answers

rake and bin/rake are both executable Ruby files used to bootstrap the Rake gem. rake is your environment's default invocation of the Rake gem and was created by RubyGems when you installed Rake. It should live somewhere in your PATH:

[jkrause:~] $ which rake
/usr/bin/rake

Or if you are using a version manager such as RVM (and you should be):

[jkrause:~] $ which rake
/Users/jkrause/.rvm/rubies/ruby-2.2.0/bin/rake

bin/rake, on the other hand, is created by Rails when you create a new Rails application and lives inside the bin directory located in the root of your Rails app:

[jkrause:~] $ ls -la ~/src/my_rails_app/bin/rake
-rwxr-xr-x  1 jkrause  staff  164 Jan  5 14:11 bin/rake

In older versions of Rails (3.x and older), bin/rake didn't exist and so standard practice was to call the default rake installed by RubyGems. With Rails 4.x, you need to call bin/rake because the Rails needs to alter the environment and load some auxiliary gems before your Rake invocation. In all honesty, I still execute rake from time to time out of habit, and I have never seen anything break, but its probably a good idea to start using bin/rake since the Rails Guides explicitly show that.

Finally, RAILS_ENV is used to set which Rails environment (development, testing, or production) that particular execution of rake or bin/rake should use.

like image 151
Joe Krause Avatar answered Aug 25 '26 09:08

Joe Krause