Keep your Heroku Ruby version and .ruby-version synchronised2 min read ruby heroku
Not everybody realizes that the
Gemfile is just another Ruby script that can contain arbitrary Ruby code. Sure, it does understand some DSL such as
source but we can use it to make our lives a bit easier if we use Heroku to deploy our app and
rvm to manage Ruby version locally.
This trick I use for my Heroku applications allows me to upgrade the Ruby version used quickly. Especially useful for doing any security-related upgrades, such as the latest Ruby 2.2.4 security release that fixes CVE-2015-7551.
Gemfile looks like below:
source 'https://rubygems.org' ruby '2.2.4' gem 'rails'
To have our
Gemfile use the
.ruby-version content to let Heroku know which version of Ruby to use, we need to read the
.ruby-version file in the
Gemfile as follows.
The code above instructs the
Gemfile to read the Ruby version from the
.ruby-version file, making it one step less to change your Ruby version, as you don’t have to update two files anymore.
chomp at the end eliminates the new-line character at the end of the number that will exist when reading the
Last modified: 23-Nov-23