Overview
With the release of Ruby 3.4.1, I tried to upgrade Ruby version 3.1.4 to 3.4.1.
The current maintenance status of Ruby versions is shown in the following picture.
https://www.ruby-lang.org/ja/downloads/branches/
Incremental version upgrades are a realistic approach, but this time, I challenged myself to upgrade directly to Ruby 3.4.1.
How I Upgraded to Ruby 3.4.1
My develop environment uses Docker containers. I modified Ruby version in three placces.
Dockerfile
FROM ruby:3.4.1-bookworm # 3.1.4-buster→3.4.1-bookworm
ENV LANG C.UTF-8
・・・(omitted)・・・
You should check Docker Hub and select a base image that suits your development environment.
.ruby-version
3.4.1 # 3.1.4→3.4.1
Gemfile
ruby '3.4.1' ###3.1.4→3.4.1
gem 'rails', '~> 7.1'
・・・(omitted)・・・
Once you finished making these modifications, please rebuild the Docker image by docker-compose build --no-cache
.
Next, you execute bundle install
in Container.If you execute this command, Gemfile.lock is modified automatically.
The Real Work Starts Here
We need to resolvethe upgrated Gemfile.lock and verify that everything works. In this post, I show the issued I personally encountered.
CI/CD process failures occurred.
Downloading net-smtp-0.5.0 revealed dependencies not in the API or the lockfile
(net-protocol (>= 0)).
Either installing with `--full-index` or running `bundle update net-smtp` should
fix the problem.
This problem already has a shared method to resolve it in a GitHub issue.
Gem::LoadError occurred
Gem::LoadError: You have already activated set 1.1.1, but your Gemfile requires set 1.1.0. Since set is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports set as a default gem. (Gem::LoadError)
This Error indicates a conflict between versions 1.1.0 and 1.1.1 of the set
library. Ruby 3.4.1 includes set version 1.1.1 by default. However, my application partially uses set version 1.1.0.
I researched the libraries included in myapplication.
As a result, I found that the fake-s3
and sorted_set
libraries are causing this issue.
These libraries depend on set version 1.1.0 and have not been maintained for a few years. Therefore, if you want to upgrade to Ruby 3.4.1, you must remove these libraries from your application.
However, fake-s3 allows us to replicate AWS S3 behavior in RSpec, so we need to find an alternative solution. In my case, I selected LocalStack to achieve the same behavior. By configuring S3::Client
in the spec_helper
file, you can switch the request target related to S3.
Warning Message Appears
active_link_to-1.0.5/lib/active_link_to/active_link_to.rb:35: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
gon-6.4.0/lib/gon/base.rb:48: warning: literal string will be frozen in the future (run with --debug-frozen-string-literal for more information)
These problem have already been reported in GitHub issue. We just need to wait for these libraries to be updated.
Fixing RSpec Failures
You need to identify and fix the RSpec failures caused by these library updates.
This process requires a lot of effort, but let's carefully go through each one step by step.
Conclusion
Upgrading from Ruby 3.1.4 to 3.4.1 was a challenging but valuable experience.
If you are planning to upgrade to Ruby 3.4.1, I recommend checking your gem dependencies beforehand and being prepared for potential compatibility issues.