

Rubygems introduced a file option to specify Ruby version in Gemfile
source link: https://blog.saeloun.com/2024/01/17/rubygems-introduced-a-file-option-to-specify-ruby-version/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Rubygems introduced a file option to specify Ruby version in Gemfile
Jan 17, 2024 1 minute read
We add ruby version in the Gemfile
or in the .ruby-version
files.
This ensures that the application runs on the correct version of Ruby.
In case of version mismatch bundler throws an error.
Your Ruby version is 3.1.0, but your Gemfile specified 3.2.2
Before
We needed to add the ruby version in the Gemfile
so the bundler uses correct ruby version or warns if incorrect ruby version is in use.
.ruby-version
file is used by tools like rvm
or rbenv
to switch the ruby version.
Gemfile
source 'https://rubygems.org'
ruby 3.2.2
.ruby-version
3.2.2
The problem with this approach is that we have to update the version in both the files.
After
Rubygems introduced a :file option that can read the Ruby version from a file.
Now its easier as we have to just update the version in the .ruby-version
file and
the Gemfile
will automatically read the version.
Gemfile
source 'https://rubygems.org'
ruby file: '.ruby-version'
.ruby-version
3.2.2
NOTE: Ensure you’re on bundler 2.5.1
or above and rubygems 3.4.20
and above.
# Update rubygems and bundler if required
gem update --system
gem -v
bundle update --bundler
bundle -v
How this works?
- The method checks if
:file
option is provided - Check if both
:file
option as well as the ruby version is provided and raise an error (Only one is required)
ruby 3.2.2, file: '.ruby-version' # ❌ This will raise an error
ruby 3.2.2 # ✅
ruby file: '.ruby-version' # ✅
- Read the ruby version from the file name provided with
:file
option - normalize the version string
Acceptable version strings are:
3.2.2
ruby-3.2.2
ruby 3.2.2
References
Share this post!
</div
Recommend
-
29
As a Rails and Ruby lover, I often search for the gem that will perfectly cover my use case. When I need to solve a problem I'm having, I want to choose the right one , the most suitable solution. Ruby...
-
108
This story starts at the console debugging a coworker’s issue. They had gotten stuck trying to run bundle install . Try, and fail. Try, and fail. And the error was really weird: C...
-
8
部署 puma 后 Gemfile 没有刷新 前段时间在使用 puma 时遇到一个大坑,相信很多人以后也会碰到。 我的某个项目的生产环境这个配置的: puma mode:cluster worker: 4 thread: 8,32 部署工具: capistra...
-
8
Better Ruby Gemfile security: A step-by-step guide using Snyk Deve...
-
5
New issue Remove legacy --skip-gemfile option from the days of Bundler opposition #42996
-
3
The Ultimate Guide to Gemfile and Gemfile.lock Aug 16, 2022 , by Keshav Biswa 11 minute read Ruby on Ra...
-
5
Gemfile of dreams: the libraries we use to build Rails appsJanuary 17, 2023
-
3
Friday, August 4, 2023 Omit webdrivers gem from new apps Gemfile, support for filtering tests by line range and more! Posted by vipulnsward Hi! This is
-
7
Ruby Weekly Issue 679 #679 — November 23, 2023 Read o...
-
8
Rails 7.1 Introduced Validate Option For Enums Jan 2, 2024 •
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK