RedBassett RedBassett - 7 months ago 33
Ruby Question

Gem "Malformed Version Number String"

I'm building a gem. I just got the basic project structure laid out, and I tried building it with

gem build my_gem.gemspec
, which worked fine. Then I installed it with
gem install My\ Gem-0.0.1.gem
and it still looked like it worked fine. Then I tried to run
and I got this:

/Users/<username>/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/version.rb:206:in `initialize': Malformed version number string on (ArgumentError)

Then I tried making some changes and saved them. I ran
gem build my_gem.gemspec
. Same error. All
, and
sub-commands are generating a stack trace with this at the top. What did I do to break all of these commands and how do I reverse it?


You should manually delete your gem:

find . -path \*my_gem\*

If everything looks good (i.e. there are no files which aren't related to your gem):

find . -path \*my_gem\* -delete

Before installing your gem again, make sure you specified version in your .gemspec.


Other locations to look for the residue of the gem:

# look for "GEM PATHS" section
gem env
# rbenv paths


Problem solved! Steps taken:

This showed where exactly is this particular Rubygems executable, which failed to load:

rbenv which gem
# => /Users/<username>/.rbenv/versions/2.2.2/bin/gem

Then it turns out under 2.2.2 directory there were cache, doc and specifications directories, all of which contained a file or sub-directory with the residue of the broken gem. Deleting them all solved the problem.