Ruby transition and packaging hints #1 - Adjusting Ruby version in commands
This is the first part of a series of short posts about issues that came up during the Ruby 3.0 transition and how to fix them. Hopefully more team members will join in and add their input.
During the Ruby 3.0 transition there are essentially two different Ruby
versions with two different binaries available, /usr/bin/ruby2.7
and
/usr/bin/ruby3.0
, while /usr/bin/ruby
points to the current default
version, which is Ruby 2.7.
In some cases the tests shipped by the source packages will use shell commands
to run scripts or Ruby code. It is imparative that in these cases the Ruby
executable is not invoked by /usr/bin/ruby
or ruby
, because this will point
to Ruby 2.7 only and fail if the tests are invoked with Ruby version 3.
The fix is to rely on RbConfig.ruby
which will point to the absolute pathname
of the ruby command for the current Ruby environment, e.g.
cmd = "#{RbConfig.ruby} ..."
This issue appeard for example in ruby-byebug
and
ruby-backports
.