Install r10k on a Foreman Server

The following occurred to me on a recent version of Foreman (i used 3.9) on a recent version of Red Hat, Alma or Rocky Linux 8 (i used 8.9). I wanted to use r10k for management of Puppet environments. When i attempted installation of r10k

/opt/puppetlabs/puppet/bin/gem install r10k

i got the following error

/opt/puppetlabs/puppet/bin/gem install r10k
ERROR: Error installing r10k:
       The last version of faraday (~> 2.0) to support your Ruby & RubyGems was 2.8.1.
       Try installing it with `gem install faraday -v 2.8.1` and then running the
       current command again

Some background: „Faraday“ is a Ruby HTTP client library and is used by r10k for accessing the Puppet Forge. The problem is that foreman still ships with Ruby 2.7, and recent versions of Faraday are not compatible with this (outdated) version of Ruby.

At the time of writing, Foreman is not compatible with Ruby 3 in general, preventing an upgrade, but an effort in that regard is underway on behalf of the Foreman developers. See here for remaining issues: Foreman Tracker #32684 „Ruby 3.0 support“.

Bottom line, the following kludge is a workaround that can be expected to go away in the foreseeable future:

/opt/puppetlabs/puppet/bin/gem install faraday -v 2.8.1
/opt/puppetlabs/puppet/bin/gem install r10k