gem install no implicit conversion of String into Integer


Here’s a puzzle

You’re coming back to your ruby environment after a hiatus doing other programming things and doing a basic gem install produces something like the following with doing any gem install operation

❯ gem install bundler -v 2.3.7
ERROR:  While executing gem ... (TypeError)
    no implicit conversion of String into Integer

# or maybe

❯ gem install bundler -v 2.3.7
ERROR:  While executing gem ... (TypeError)
    no implicit conversion of String into Integer

        s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
                                        ^^^^^^^^^^^^^^^
        /Users/tpowell/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/net-http-0.4.1/lib/net/http.rb:1666:in `initialize'

SSL Verify Mode in the .gemrc

The ~/.gemrc file had a setting on the problem environment for ssl_verify_mode, but it turned out to be a string "0" instead of a 0 or 1. (My systems didn’t have a .gemrc file and defaulted to 1

---
:ssl_verify_mode: "0"

What is the format of the .gemrc and how does it get set?

The Gem::ConfigFile can be placed in /etc/gemrc (system wide), ~/.gemrc (per user), or in files listed in GEMRC environment variable. It’s in a YAML format, where string keys specify command options (the below for gem install and gem update)

install: --no-rdoc --no-ri
update: --no-rdoc --no-ri

The gem key will set options for all gem commands:

gem: --no-rdoc --no-ri

…and symbol keys specify RubyGems options:

:sources:
  - https://rubygems.org
  - https://internalrubygemsserver.example.com

As for how a .gemrc could get set outside of hand editing, some gem commands such as gem sources -a SOURCE_URI can add values to the file.

No longer a problem on 3.3.4

On trying this on a different machine, I noticed that Ruby 3.3.4 doesn’t seem to have a problem.

❯ gem install bundler -v 2.3.7
Successfully installed bundler-2.3.7
Parsing documentation for bundler-2.3.7
Done installing documentation for bundler after 0 seconds
1 gem installed

The openssl gem upgraded from 3.1.0 to 3.2.0 between Ruby 3.2.2 and 3.3.4 (and the OpenSSL library did as well, but the error happened in Ruby code, so I suspect it’s handled there now.


Leave a Reply