We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
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
to our projects so that
version manager tools
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
and also add the Ruby version to Gemfile
by default after creating an app.
Let's create a new project with Ruby 2.5 .
1$ rvm list default 2 3 Default Ruby (for new shells) 4 5 ruby-2.5 [ x86_64 ] 6 7 8$ 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
Also, we should see following line
in the Gemfile.