Upgrade Rails from 5.2 to 6.0

Upgrade Rails from 5.2 to 6.0

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

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

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

1. Preparations

Before beginning with the upgrade process, we have some recommended preparations:

  • Your Rails app should have the latest patch version opens a new window before you move to the next major/minor version.
  • You should have at least 80% test coverage unless you have a dedicated QA team.
  • Follow a Git flow workflow to actively manage at least two environments: staging and production.
  • Check your Gemfile.lock for incompatibilities by using RailsBump opens a new window .
  • Create a dual boot mechanism, the fastest way to do this is installing the handy gem next_rails opens a new window .

For full details check out our article on How to Prepare Your App for a Rails Upgrade opens a new window .

2. Ruby version

Rails 6.0 opens a new window requires Ruby 2.5 opens a new window or later. Check out this table opens a new window 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 opens a new window . You can use this task as a guideline as explained thoroughly in this post opens a new window .

As an alternative, check out RailsDiff opens a new window , 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
Action View
Active Record

6. Webpacker

Webpacker opens a new window is now opens a new window the default JavaScript compiler for Rails 6. You can still manage your JavaScript using the Asset Pipeline opens a new window 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 opens a new window

7. Credentials

Rails 6 adds support opens a new window 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 opens a new window .

Get the book