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

+3


source to share


2 answers


  • rake

    and bin/rake

Rake is a program that you have installed on your computer. To use it in a terminal, use rake do:something

. Using directly rake

means that a shortcut has been created, an alias that says "when I type rake

, I want to use the program located at [...]".

The style bin/rake

does not use the generated alias, but the program path. Usually the executor of the program (not the contents of the program, just the launcher) is located in the folder /bin/

. To find the full path to a specific program, use which

:

[yoshiji:~] $ which rake
/home/yoshiji/.rvm/gems/ruby-1.9.3-head@yourproject/bin/rake
[yoshiji:~] $ which ls
/bin/ls

      

  • RAILS_ENV=production rake do:something



This part RAILS_ENV

is for specifying the environment that Rails should load when running the command rake

. The default is Wednesday development

.


Summarizing:

  • rake assets:precompile

    : use an alias / shortcut rake

  • /bin/rake assets:precompile

    : use the full path to the program rake

  • RAILS_ENV=production rake assets:precompile

    : tell Rails to load the environment production

    when executing the rake taskassets:precompile

+2


source


rake

and bin/rake

are the Ruby executables used to load Rake faces. rake

is the default environment call for the Rake Gem and was created by RubyGems when Rake was installed. It should live somewhere in your PATH:

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

      

Or, if you are using a version manager like 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 a directory bin

located at the root of your Rails application:

[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

did not exist, so the standard practice was to call the default rake

installed RubyGems. With Rails 4.x, you need to call bin/rake

because Rails needs to change the environment and load some helper gems before your Rake call. To be honest, I still do rake

it from time to time out of habit, and I've never seen anything break, but it's probably a good idea to start using bin/rake

it since the Rails Guides clearly show this.

Finally, it is RAILS_ENV

used to set up the Rails environment (development, testing, or production) that a particular runtime rake

or bin/rake

.

+4


source







All Articles