---
title: "Rails 5.2 sets version in Gemfile & adds .ruby-version"
description:
  "Rails 5.2 sets Ruby version in Gemfile and adds.ruby-version file by default."
canonical_url: "https://www.bigbinary.com/blog/rails-5_2-adds-ruby-version-file-and-ruby-version-to-gemfile-by-default"
markdown_url: "https://www.bigbinary.com/blog/rails-5_2-adds-ruby-version-file-and-ruby-version-to-gemfile-by-default.md"
---

# Rails 5.2 sets version in Gemfile & adds .ruby-version

Rails 5.2 sets Ruby version in Gemfile and adds.ruby-version file by default.

- Author: Mohit Natoo
- Published: May 7, 2018
- Categories: Rails 5.2, Rails

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](https://rvm.io/workflow/projects#project-file-ruby-version)
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](https://devcenter.heroku.com/articles/ruby-versions).
This will help bundler install dependencies scoped to the specified Ruby
version.

### Good News! Rails 5.2 makes our work easy.

In Rails 5.2,
[changes have been made](https://github.com/rails/rails/pull/30016) 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 .

```ruby
$ 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
ruby "2.5"
```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5_2-adds-ruby-version-file-and-ruby-version-to-gemfile-by-default)
