May 7, 2018
This blog is part of our Rails 5.2 series.
For Ruby developers, it's common to switch between multiple Ruby versions for
multiple projects as per the needs of the project. Sometimes, the process of
going back and forth with multiple Ruby versions could be frustrating for the
developer. To avoid this we add
.ruby-version files
to our projects so that version manager tools such as rvm
, rbenv
etc. can
easily determine which Ruby version should be used for that particular project.
One other case that Rails developers have to take care of is ensuring that the Ruby version used to run Rails by the deployment tools is the one that is desired. In order to ensure that we add ruby version to Gemfile. This will help bundler install dependencies scoped to the specified Ruby version.
In Rails 5.2,
changes have been made to introduce
.ruby-version
file and also add the Ruby version to Gemfile by default after
creating an app.
Let's create a new project with Ruby 2.5 .
$ rvm list default
Default Ruby (for new shells)
ruby-2.5 [ x86_64 ]
$ rails new my_new_app
In our new project, we should be able to see .ruby-version
in its root
directory and it will contain value 2.5
. Also, we should see following line in
the Gemfile.
ruby "2.5"
If this blog was helpful, check out our full blog archive.