Upgrading Ruby, Bundler and Installing Rails 7

We’ve been working on upgrading a project to Rails 7. The app hadn’t been updated in a while, and it was running Ruby 2.6 and bundler 1.17. In order to do the Rails upgrade we had to do three things: Update Ruby, update Bundler & update Rails.

Dealing with all three dependencies can be tricky so here’s a quick guide to managing the upgrade.

1. Update Ruby

Rails 7 depends on Ruby 2.7 or higher. Our app was running on an older version so we upgraded that first. We use rbenv but the upgrade process is similar for other Ruby version managers. Amend your .ruby-version file to 2.7.5 (the latest 2.7 at the time of writing) and run rbenv install 2.7.5.

2. Updating Bundler

After installing a new Ruby version, you’ll need to install bundler. In our case, we decided to take the opportunity to upgrade from Bundler v1 to v2. We could, potentially, have gotten away with installing v1 again but we thought using the latest version would avoid any Ruby 2.7 conflicts.

To update bundler, run bundle update --bundler. This will update the BUNDLED WITH section of your Gemfile.lock. You can read more about the Bundler v1 to v2 upgrade on bundler.io.

3. Installing Rails 7

Now for the tricky part, you need to install Rails 7 and update all of your gems to be compatible. Our approach is as follows:

  1. Update Rails in the Gemfile to specify v7: gem 'rails', '~> 7.0.0'
  2. Run bundle and see if it works. If so, 🎉 you’re done. If not, continue to step 3
  3. Comment out all your gems, except Rails. Run bundle to make sure it passes
  4. Gradually uncomment your gems, re-running bundle each time. This helps isolate problems and allows you to fix them one at a time.