Upgrade Rails from 5.2 to 6.0

This article is part of our Upgrade Rails series. To see more of them, click here.

This article will cover the most important aspects that you need to know to get your Ruby on Rails application from version 5.2 to 6.0.

  1. Considerations
  2. Ruby version
  3. Gems
  4. Config files
  5. Removals
  6. Webpacker
  7. Credentials
  8. Next steps

1. Considerations

Before beginning with the upgrade process, we recommend that each version of your Rails app has the latest patch version before moving to the next major/minor version. For example, in order to follow this article, your Rails version should be at 5.2.3 before upgrading to Rails 6.0.x

2. Ruby version

Rails 6.0 requires Ruby 2.5 or later. Check out this table to see all the required Ruby versions across all Rails versions.

3. Gems

Make sure you check the Github page of the gems you use for the project to find out its compatibility with Rails 6.0. In case you own the gem, you'll need to make sure it supports Rails 6.0 and if it doesn't, update it.

4. Config files

Rails includes the rails app:update task. You can use this task as a guideline as explained thoroughly in this post.

As an alternative, check out RailsDiff, which provides an overview of the changes in a basic Rails app between 5.2.x and 6.0.x (or any other source/target versions).

5. Removals

Railties
Action Pack
  • Remove deprecated fragment_cache_key helper in favor of combined_fragment_cache_key.

  • Remove deprecated methods in ActionDispatch::TestResponse: #success? in favor of #successful?, #missing? in favor of #not_found?, #error? in favor of #server_error?

Action View
  • Remove deprecated image_alt helper.

  • Remove an empty RecordTagHelper module from which the functionality was already moved to the record_tag_helper gem.

Active Record

6. Webpacker

Webpacker is now the default JavaScript compiler for Rails 6. You can still manage your JavaScript using the Asset Pipeline but it might be a good idea to start migrating to Webpack.

There is a really good screencast that explains everything about it: How to Use Javascript via Webpacker in Rails 6

7. Credentials

Rails 6 adds support for multi environment credentials. That means that now you can run rails credentials:edit --environment staging and it will create a config/credentials/staging.yml.enc file where you can store your encrypted credentials for staging (or whatever environment you want). Rails will know which credential file should use based on the format of the file. Also, if you create an environment credential file, it will take precedence over the default config/credentials.yml.enc.

8. Next steps

If you successfully followed all of these steps, you should now be running Rails 6.0! Do you have any other useful tips or recommendations? Did we miss anything important? Share them with us in the comments section.

If you're not on Rails 6.0 yet, we can help! Download our free eBook: The Complete Guide to Upgrade Rails.

Get the book