3

I'd like to use a specific version of ruby when running my app in production on Heroku.

As explained here, you only have to add a line like ruby "2.0.0" in your Gemfile.

However, as I use RVM locally, I already specified the ruby version to use in a .ruby-version file in the root directory of the project that only contains the line ruby-2.0.0-p0.

To avoid code duplication, I'd like the version to be specified in only one place, so that I'm sure that the same version is always used in development and on Heroku.

Is there a way to do that ?

Community
  • 1
  • 1
Daniel Ristic
  • 710
  • 6
  • 16

2 Answers2

6

The Gemfile is ruby code, so you can write some ruby to read the version from .ruby-version and pass that value to the ruby method, rather than a hard-coded version string.

If the .ruby-version file is in the same directory, something like this should work:

ruby File.read(".ruby-version").strip.split("-").first

If the .ruby-version file contains "1.9.3-p327", for example, that line would be equivalent to:

ruby "1.9.3"
Rick Fletcher
  • 528
  • 3
  • 11
0

No, you can't specify the patch level to be used on Heroku - they manage patch levels for you. You need to track their changelog to know when patch levels change. So you need to make sure you are using the same patch level locally which for Ruby 2.0.0 it's present p195.

John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • Sorry I did not make myself clear I am not trying to specify the patchlevel used on Heroku but extract the version from the .ruby-version file and use it in the Gemfile, so that it the .ruby-version contains 1.9.3-psomething, the 1.9.3 is used and if I specify 2.0.0-psomething the 2.0.0 is used. – Daniel Ristic Jun 03 '13 at 11:59
  • 1
    You can only do this with the gemfile, so, duplication required :( This feature request was opened, but is unlikely to be acted on. Seems rvm can read from the Gemfile? https://github.com/heroku/heroku-buildpack-ruby/issues/63 – catsby Jun 03 '13 at 15:46