Specifying a Ruby Version
Last updated 22 February 2016
Table of Contents
Selecting a version of Ruby
You’ll need to install
1.2.0 of bundler to use the
See a complete list of supported Ruby versions
You can use the
ruby keyword in your app’s
Gemfile to specify a particular version of Ruby.
source "https://rubygems.org" ruby "2.2.4" # ...
When you commit and push to Heroku you’ll see that Ruby
2.2.4 is detected:
-----> Heroku receiving push -----> Ruby/Rack app detected -----> Using Ruby version: 2.2.4 -----> Installing dependencies using Bundler version 1.7.11 ...
For specifying non MRI ruby engines, you’ll need to use the
:engine_version options. You can specify JRuby by using the following line:
ruby "2.2.2", :engine => "jruby", :engine_version => "126.96.36.199"
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.
Specifying a Ruby version via the environment
Gemfiles are actually just Ruby code, so you can also specify your Ruby version in the environment. For example:
ruby ENV['CUSTOM_RUBY_VERSION'] || '2.2.4'
Would let you specify a Ruby version in the
CUSTOM_RUBY_VERSION environment variable, or default to
2.2.4 if it’s not set. This is handy if you are running your app through a continuous integration tool and want to ensure it checks your codebase against other versions of Ruby, but restrict it to a certain version when deployed to Heroku.
Changing environment variables does not recompile your app. For a Ruby version change to take effect through this method, you’ll need to deploy the app again since Ruby is vendored into each slug.
Applications that migrate to a non-default version of Ruby should have
bin be the first entry in their
PATH config var. The Ruby buildpack sets this value and you should not modify it. This var’s current value can be determined using
$ heroku run bash $ env | grep PATH PATH=/app/bin:/app/vendor/bundle/bin:/app/vendor/bundle/ruby/2.2.0/bin:bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin```
If absent or not the first entry you should ensure you’re using the supported version of the Ruby buildpack. If you are, please open a support ticket.
PATH is set correctly you will see the expected version using
$ 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]
PATH is not setup correctly, you might see this error:
Your Ruby version is 1.9.2, but your Gemfile specified 1.9.3
If your PATH is setup correctly you may get this error if you have an improper hashbang (#!) line committed. For example in
bin/bundle starts with this:
#!/usr/bin/env ruby1.9.1 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle')
It will attempt to use the wrong version of Ruby. Make sure your first line does not specify a version like this:
#!/usr/bin/env ruby ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle')
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
$ gem install bundler