Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require a specific version of RubyGems

Tags:

ruby

rubygems

I want to have a specific version of RubyGems for a project. I have tests that fail for 2.5.x but pass for 2.6.x, so I want to make sure users are using 2.6.x or higher. I know you can explicitly update the version of RubyGems, but can you somehow 'require' a specific version like you can for regular gems?

like image 541
Ferdinand van Wyk Avatar asked Sep 17 '25 06:09

Ferdinand van Wyk


1 Answers

I don't believe it's possible to select from among multiple rubygems versions in a single Ruby installation. But you can ensure that the required version is being used. Put the following somewhere where it will be run early in your application's startup, such as the top of your Gemfile (which is just a Ruby file), or at the beginning of a script which doesn't use bundler:

required_rubygems_version = '2.6.0'
if Gem.rubygems_version < Gem::Version.create(required_rubygems_version)
  raise "Please upgrade to rubygems #{required_rubygems_version}"
end
like image 112
Dave Schweisguth Avatar answered Sep 20 '25 00:09

Dave Schweisguth