Not everybody realises 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 is one trick that I use for my Heroku applications that allows me to quickly upgrade the Ruby version used. 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 this:
source 'https://rubygems.org' ruby '2.2.4' gem 'rails'
.ruby-version like this:
In order to have our
Gemfile use the
.ruby-version content to let Heroku know which version of Ruby to use, just edit the
Gemfile as follows.
This instructs the
Gemfile to read the Ruby version from the
.ruby-version file, making it that one step less to change your Ruby version, as you don’t have to update two files anymore!