---
title: "Rails 5 wraps all rake commands using rails"
description:
  "In Rails 4 some commands use rake and some commands use rails. Rails 5 brings
  consistency by having rails command to do everything."
canonical_url: "https://www.bigbinary.com/blog/rails-5-supports-rake-commands-using-rails"
markdown_url: "https://www.bigbinary.com/blog/rails-5-supports-rake-commands-using-rails.md"
---

# Rails 5 wraps all rake commands using rails

In Rails 4 some commands use rake and some commands use rails. Rails 5 brings
consistency by having rails command to do everything.

- Author: Mohit Natoo
- Published: January 14, 2016
- Categories: Rails 5, Rails

In Rails 4 some commands start with `rails` and some commands start with `rake`.
This could be quite confusing for people new to Rails. Let's see an example.

Our task is to write a database migration and then to run that migration.

```ruby

rails g migration create_users

```

Above command creates a migration. Now we need to run that migration.

```ruby

rake db:migrate

```

As you can see first command starts with `rails` and second command starts with
`rake`.

In order to consolidate them we can either use `rails` for everything or we can
use `rake` for everything.

## Choosing rails command over rake command

Some favor using `rake` over `rails`. But an important feature missing in Rake
is the ability to pass arguments.

```ruby

rails console development

```

In order to execute the above command using `rake` we will have to pass
`console` and `development` as arguments. We can pass these values using
environment variables. That would mean adding additional code in Rake task to
fetch right values and then only we will be able to invoke command
`rails console development`.

## Rails 5 enables executing rake commands with rails

Rails core team [decided](https://github.com/rails/rails/pull/22288) to have
consistency by enabling `rails` command to support everything that `rake` does.

For example in Rails 5 commands like `db:migrate`, `setup`, `test` etc which are
part of `rake` command in Rails 4 are now being supported by `rails` command.
However you can still choose to use `rake` to run those commands similar to how
they were run in Rails 4. This is because Rails community has
[introduced Rake Proxy](https://github.com/rails/rails/blob/f718e52bcce02bc137263ead3a9d9f5df1c42c37/railties/lib/rails/commands/rake_proxy.rb)
instead of completely moving the command options from `rake` to `rails`.

What happens internally is that when `rails db:migrate` command is executed,
Rails checks if `db:migrate` is something that `rails` natively supports or not.
In this case `db:migrate` is not natively supported by `rails`, so Rails
delegates the execution to Rake via Rake Proxy.

If you want to see all the commands that is supported by `rails` in Rails 5 then
you can get a long list of options by executing `rails --help`.

### Use app namespace for framework tasks in Rails 5

As `rails` command is now preferred over `rake` command, few rails namespaced
framework tasks started looking little odd.

```bash

$ rails rails:update

$ rails rails:template

$ rails rails:templates:copy

$ rails rails:update:configs

$ rails rails:update:bin

```

So, Rails team decided to change the namespace for these tasks from `rails` to
`app`.

```bash

$ rails app:update

$ rails app:template

$ rails app:templates:copy

$ rails app:update:configs

$ rails app:update:bin

```

Using `rails rails:update` will now give deprecation warning like:
`DEPRECATION WARNING: Running update with the rails: namespace is deprecated in favor of app: namespace. Run bin/rails app:update instead`.

## More improvements in pipeline

In Rails 4, the routes are usually searched like this.

```plaintext

$ rake routes | grep pattern

```

There [is an effort underway](https://github.com/rails/rails/issues/18902) to
have a Rails command which might work as shown below.

```plaintext

$ rails routes -g pattern

```

There is also
[an effort to enable lookup for controller](https://github.com/rails/rails/pull/20420)
like this.

```plaintext

$ rails routes -c some_controller

```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-supports-rake-commands-using-rails)
