哪个 Ruby on Rails 与哪个 Ruby 版本兼容?

我有一个旧的2.1.1 Ruby on Rails 应用程序,系统升级为使用 Ruby1.8.7。它最初使用的是1.8.5左右。

出于性能考虑,我想把它升级到 Ruby 1.9. x,也可能升级到更新的 Ruby on Rails。

我找不到任何关于不同 Ruby 版本和 RubyonRails 版本之间兼容性的简单图表。

2.1.1能与 Ruby1.9.x 一起工作吗?如果没有,那么我需要先升级它到什么程度,我可能会遇到什么样的问题?我的应用程序对数据库层执行复杂的操作,但其余的操作相当简单。

64783 次浏览

From Rails 2.2 release note: (not exactly the one you asked)

Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.

I would believe that Rails 2.1.1 isn't compatible with Ruby 1.9, and you would be on your own in such an environment. You can give it a shot if your test suit is comprehensive, of course. Also, you'd have to check all the other gems used in the project which could be a real hassle.

If you choose to stick with this Rails version, I wouldn't migrate to 1.9.x. As you mentioned you would prefer upgrading it, you should probably go through the deprecations mentioned in Rails 3.0 release notes and adapt your code. A summarized list can be found in Rails 3 deprecated methods and APIs

Its difficult to find it in release notes. After googling for some time, I could only find it here http://www.devalot.com/articles/2012/03/ror-compatibility

Ruby Rails Version Compatibility

For versions < 3.2: http://www.devalot.com/articles/2012/03/ror-compatibility

For versions >= 4.0:

  • Rails 4 recommends 2.0 (src: Rails blog)
  • Rails 4.1/4.2 recommends 2.1 (src: Rails former download page)
  • Rails 4.2.1 recommends 2.2 (src: Rails former download page)
  • Rails 5.0 requires 2.2.2+ (Rails blog)

Rails 3.2

I tried stepping out of those recommendations (mainly running Rails 3.0 on Ruby 2.0 and 2.1), I ran in multiple weird issues.

In general there are two places to check if a Ruby platform is suitable for your preferred Rails version.

  1. The release announcement in the Rails blog
  2. The release notes in the guides/source directory (also on the web at Rails Guides and Github )

You might also find it useful to look at the .travis.yml file of your version. The rvm entry there suggests the Ruby versions that the developers might run automated tests against.

Naturally, use their recommendations alongside your own testing.

Rails Guides has information under "Getting Started with Rails". I've pull information from each version of the guides:

Rails 3.2 - The Ruby language version 1.8.7 or higher
Rails 4.0 - The Ruby language version 1.9.3 or newer
Rails 4.1 - The Ruby language version 1.9.3 or newer
Rails 4.2 - The Ruby language version 1.9.3 or newer

As far as I can tell this is as close to a primary source as you can get for minimum versions. See gamov's answer for recommended versions.

The Rails Guide on Upgrading Ruby on Rails has a section on Ruby versions. This is probably the best source as it is controlled by the Rails core team.

As of August, 2016, the Rails Guide reads:

1.3 Ruby Versions

Rails generally stays close to the latest released Ruby version when it's released:

  • Rails 5 requires Ruby 2.2.2 or newer.
  • Rails 4 prefers Ruby 2.0 and requires 1.9.3 or newer.
  • Rails 3.2.x is the last branch to support Ruby 1.8.7.
  • Rails 3 and above require Ruby 1.8.7 or higher. Support for all of the previous Ruby versions has been dropped officially. You should upgrade as early as possible.

This is an old question, but the fact that rails is tested against a version of ruby is a good indication that it should work on that version of ruby.

Since 9th April 2019, stable branches of Rails use Buildkite for automated testing, and the list of tested ruby versions, by rails branch, is:

Rails 6.1

  • >= 2.5.0

Rails 6.0

  • >= 2.5.0

Rails 5.2

Rails 5.1

  • >= 2.2.2

Rails 5.0

  • >= 2.2.2

Rails 4.2

  • >= 1.9.3

Rails 4.1

  • >= 1.9.3

Prior to 9th April 2019, stable branches of Rails since 3.0 use travis-ci for automated testing, and the list of tested ruby versions, by rails branch, is:

Rails 3.0

  • 1.8.7
  • 1.9.2
  • 1.9.3

Rails 3.1

  • 1.8.7
  • 1.9.2
  • 1.9.3

Rails 3.2

  • 1.8.7
  • 1.9.2
  • 1.9.3
  • 2.0.0
  • 2.1.8
  • 2.2.6
  • 2.3.3

Rails 4.0

  • 1.9.3
  • 2.0.0
  • 2.1
  • 2.2

Rails 4.1

  • 1.9.3
  • 2.0.0
  • 2.1
  • 2.2.4
  • 2.3.0

Rails 4.2

  • 1.9.3
  • 2.0.0-p648
  • 2.1.10
  • 2.2.10
  • 2.3.8
  • 2.4.5

Rails 5.0

  • 2.2.10
  • 2.3.8
  • 2.4.5

Rails 5.1

  • 2.2.10
  • 2.3.7
  • 2.4.4
  • 2.5.1

Rails 5.2

  • 2.2.10
  • 2.3.7
  • 2.4.4
  • 2.5.1

Rails 6.0

  • 2.5.3
  • 2.6.0

(From https://www.hmallett.co.uk/2018/08/ruby-and-ruby-on-rails-version-compatibility/)

All those pages get behind of the current state. And the documentation on the official docs are vague 'The Ruby language version ... or higher'. If you want to know what Ruby versions the Rails version you would like to know is tested against check the Travis CI that the Rails community is using. Here you can see which branch is tested agains which Ruby version.

Edit:

Like hmallett mentioned Rails has changed to another testing suite. It has been changed to Built kite. You can always check the Code Status at the source repository.

the first answer here is quite informative, but I have a comment on the compatibility of rails-4.2 with ruby-2.4.5, as there is an issue shown here, that issue makes rails-2.4.8 only compatible with ruby-2.4+, any other version of rails-2.4 will not work.

I believe this regression says that Rails 4.1 can't work with Ruby 2.3: https://bugs.ruby-lang.org/issues/12353

The newest (at present) Ruby on Rails 7.0 requires Ruby 2.7.0+ and prefers Ruby 3.0+ (source).