Specifying a Ruby Version

Last Updated: 28 November 2013

ruby

Table of Contents

If you have questions about Ruby on Heroku, consider discussing it in the Ruby on Heroku forums.

Selecting a version of Ruby

You’ll need to install 1.2.0 of bundler to use the ruby keyword.

See a complete list of supported Ruby versions

You can use the ruby keyword of your app’s Gemfile to specify a particular version of Ruby.

source "https://rubygems.org"
ruby "1.9.3"
# ...

When you commit and push to Heroku you’ll see that Ruby 1.9.3 is detected:

-----> Heroku receiving push
-----> Ruby/Rack app detected
-----> Using Ruby version: 1.9.3
-----> Installing dependencies using Bundler version 1.2.1
...

For specifying non MRI ruby engines, you’ll need to use the :engine and :engine_version options. You can specify JRuby by using the following line:

ruby "1.9.3", :engine => "jruby", :engine_version => "1.7.8"

Please see Ruby Support for a list of available versions.

If you were previously using RUBY_VERSION to select a version of Ruby, please follow the instructions above to specify your desired version of Ruby using Bundler.

Troubleshooting

Migration

Applications that migrate to a non-default version of Ruby should have bin be the first entry in their PATH config var. This var’s current value can be determined using heroku config.

$ heroku config -s | grep PATH
PATH=vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin

If absent or not the first entry, add bin: to the config with heroku config:set.

$ heroku config:set PATH=bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin

If the PATH is set correctly you will see the expected version using heroku run:

$ heroku run "ruby -v"
Running `ruby -v` attached to terminal... up, run.1
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

If the PATH is not setup correctly, you might see this error:

Your Ruby version is 1.9.2, but your Gemfile specified 1.9.3

Bundler

If you’re using a Bundler 1.1.4 or lower you’ll see the following error:

undefined method `ruby' for #<Bundler::Dsl:0x0000000250acb0> (NoMethodError)

You’ll need to install bundler 1.2.0 or greater to use the ruby keyword.

$ gem install bundler