Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gem update --system failure

Running gem update --system fails with the following error:

#22 71.91 ERROR:  Error installing rubygems-update:
#22 71.91   There are no versions of rubygems-update (= 3.5.2) compatible with your Ruby & RubyGems
#22 71.91   rubygems-update requires Ruby version >= 3.0.0. The current ruby version is 2.7.5.203.
#22 71.91 ERROR:  While executing gem ... (NoMethodError)
#22 71.91     undefined method `version' for nil:NilClass
#22 71.93 Updating rubygems-update

My ruby version is:

rbenv local:
2.7.5

Do I need to find the compatible version of rubygems-update with ruby 2.7.5 and install it?

like image 494
shahram kalantari Avatar asked Mar 17 '26 09:03

shahram kalantari


1 Answers

Either you can go to the RubyGems version list of rubygems-update, and click on each one until you find a version that matches your Ruby version criteria (<= 2.7.5), or then we play programmer and do it the fun way:

require 'open-uri'
require 'json'

GEM_TO_TEST           = "rubygems-update"
RUBY_VERSION_TO_MATCH = "2.7.5"

API_URL = "https://rubygems.org/api/v1/versions/#{GEM_TO_TEST}.json"

# Load list of all available versions of GEM_TO_TEST
gem_versions = JSON.parse(open(API_URL).read)

# Process list to find matching Ruby version
matching_gem = gem_versions.find { |gem|
  Gem::Dependency.new('', gem['ruby_version']).
    match?('', RUBY_VERSION_TO_MATCH)
}

puts "Latest version of #{GEM_TO_TEST} " +
     "compatible with Ruby #{RUBY_VERSION_TO_MATCH} " +
     "is #{matching_gem['number']}."

If we run that, out comes:

Latest version of rubygems-update compatible with Ruby 2.7.5 is 3.4.22.

Therefore the solution to your problem is (most likely):

gem update --system 3.4.22
like image 66
Casper Avatar answered Mar 19 '26 23:03

Casper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!