20

I have an existing Ruby on Rails project. How do I find out which version of Ruby is originally used for the application?

Edit: To sum up this thread: If there are no ruby-version specific gems, every Ruby should work. All your posts were helpful - Thanks.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Stephan
  • 1,639
  • 3
  • 15
  • 26

5 Answers5

9

If no version-specific gems are in use, I'm not sure it's possible to determine the exact ruby version used during development. In any case, the app may work fine against several versions, depending on the features it has.

If the app has comprehensive tests, you could just work back to find the latest version for which all the tests pass.

Checking the minimum version of Ruby compatible with the Rails version used would also help to narrow the field.

Mike Woodhouse
  • 51,832
  • 12
  • 88
  • 127
5

The answers above are split between two cases:

  1. Where the app is still running (in production or otherwise), where you can connect to production console and check the version
  2. Where the only "artifact" available is the app source code in source control

For #2, the answers above cover it pretty much. You guys are lucky.

For #1, its more of an archealogical expedition. I believe the OP is in that situation and I was in a similar situation today.

Looking at the gem versions is probably the best way to do it.

Here are a few clues that can be used, for everyone's reference. (For the benefit of those who stumble upon this article in the future):

Signs the app was built in Ruby 1.8.7

  • Existence of SystemTimer Gem in the Gemfile.lock (1)
  • Existence of ruby-debug in GemFile, as opposed to ruby-debug19 for 1.9. I believe this could also mean 1.8.6

Signs the app was built in Ruby 1.9

  • Existence of ruby-debug19 in Gemfile
  • String#force_encoding is used
  • encoding: utf-8 at the top of each page

Signs the app was built with jruby

  • Usage of ffi

In General if you read through the old "migration guides from 1.8.7 to 1.9" which lists the differences, you can use those differences to help you find clues. See:

This SO question:

What is the difference between Ruby 1.8 and Ruby 1.9

and this airbnb blog post:

http://nerds.airbnb.com/upgrading-from-ree-187-to-ruby-193/

Good luck!

(1): "Using this gem in Ruby 1.9 is useless and does not make any sense! System Timer is trying to work around some limitation of the "green thread" model used in Ruby 1.8 (MRI). See http://ph7spot.com/musings/system-timer for more details." A drop-in replacement for SystemTimer is timeout.rb from Ruby core.Oct 21, 2011" source: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=systemtimer%20gem

Community
  • 1
  • 1
Gal
  • 5,537
  • 1
  • 22
  • 20
5

Some people use rvm to manage gemsets in their projects, in this case .rvmrc contains this information, like: "ruby-1.9.2-p180@projectname"

Jake Jones
  • 1,170
  • 1
  • 11
  • 15
3

For me, I logged into the server where the project was hosted to see what version was installed there: ruby --version

Josh M.
  • 26,437
  • 24
  • 119
  • 200
1

Check if it uses ruby1.9 only gem files, like ruby-debug19, or, conversely, gems which are for 1.8 only. See if String#force_encoding is used - it can hint that it's 1.9. Other 1.9 features are less commonly used AFAIK.

Roman
  • 13,100
  • 2
  • 47
  • 63