22

I am running an application on Rails 2.3.8. I am planning to upgrade it to Rails 4.0 (which is in RC). What will be the easiest way for me to do this? Do I need to first upgrade to Rails 3.x?

Note: in my current implementation, I am using starling and ferret; as part of upgrade I am also considering to move to sidekiq and sunspot

nit
  • 321
  • 2
  • 4
  • 4
    "Do I need to first upgrade to Rails 3.x" - that depends on your threshold for acceptable pain :). In general, breaking up large changes into smaller incremental changes is a recommended approach. – PinnyM Jun 17 '13 at 14:16
  • 4
    Also, you should certainly try to upgrade to the latest 2.3.x before moving to either 3.x or 4. – PinnyM Jun 17 '13 at 15:27
  • you will most probably need to upgrade your ruby as well – Nick Ginanto Jul 14 '13 at 16:20
  • 3
    I really hope you have a decent test coverage before you dive into that. Even a non-decent coverage will help keep your heart rate within a healthy range. – Marcelo De Polli Jul 15 '13 at 01:04

2 Answers2

51

This is a multi-step process, and depending on the size of your application, it can take a long time. At each step, you'll want to test your application for bugs and problems and broken gems (because they are most certainly going to crop up). I have included links for the most complicated steps. Here is the path of least pain:

Update to Rails 2.3.18.

Update to Ruby 1.9.3.

Update to Rails 3.0.

Update to Rails 3.1.

Update to Rails 3.2.latest.

Update to Ruby 2.0.latest.

Update to Rails 4.0.

Update from Rails 4.0 to Rails 4.1.

Update from Rails 4.1 to Rails 4.2.

Update from Rails 4.2 to Rails 5.0.

Update from Rails 5.0 to Rails 5.1.

Bonus: If you have a large application, this is going to take a long time. If you have a large team, long-running branches become a huge headache because of recurring merge conflicts. One strategy for mitigating this is to dual boot your application with both versions of Rails so that you can have the new version running on your master branch, rather than on a long-running branch of its own.

Aaron Gray
  • 11,283
  • 7
  • 55
  • 61
  • 1
    Hi. Just out of interest, why do you upgrade to Ruby 1.9.3 before upgrading to Rails 3.0? Rails 2.3 doesn't support Ruby 1.9 out of the box, whereas Rails 3 does, so does this approach create additional work to make Rails 2.3 work with Ruby 1.9? – robd Feb 27 '14 at 18:24
  • 2
    Good point. You can definitely upgrade to Rails 3 before moving to Ruby 1.9. In our case, we had a large application, and moving from Ruby 1.8.7 to 1.9 was far less work than moving from Rails 2.3 to 3.0. It took us a couple months to get on 1.9, but over a year to get on 3.0. So, we went with the easier update first to give us the performance benefits and gem compatibility of Ruby 1.9 sooner. – Aaron Gray Feb 27 '14 at 21:07
  • OK, interesting. I had wondered if going to ruby 1.9 first might be the right thing to do for performance reasons - hadn't considered gem compatibility. I'll try the rails upgrade first and see how I get on. – robd Feb 27 '14 at 21:29
  • To follow up here, I upgraded the whole way through to latest Rails 3.2 under Ruby 1.8.7, but I found the performance was so bad that I had to upgrade to Ruby 1.9.3 anyway before going to production. So I would recommend upgrading to Rails 3.0 first, then Ruby 1.9.3 (for gem compatibility and performance benefits mentioned by @aaron), and then rails 3.1, 3.2. – robd May 22 '14 at 10:45
  • Links to guide lead to 404's – NameIsPete Feb 09 '16 at 15:11
  • 1
    Thanks for the heads-up. I've updated the two dead links to use the Wayback Machine so they can be accessed again. – Aaron Gray Feb 09 '16 at 18:57
2

Aaron Gray's answer is very useful, but sometimes it's very difficult after upgrading to find the differences between rails version in the code. I mean, many times after upgrading something doesn't work. Maybe could be some changes in the file or some file could be added or removed in newer version. There is a nice tool, how you can find out all differences between version and compare them. It's on Rails differences and could be very helpful to discover some potential mistakes and bugs.

Marko Krstic
  • 1,417
  • 1
  • 11
  • 13