Gem "Malformed Version Number String" - ruby

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 irb and I got this:
/Users//.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/version.rb:206:in `initialize': Malformed version number string on (ArgumentError)
I tried making some changes and saved them. I ran gem build my_gem.gemspec. Same error.
All irb, rails, and gem 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:
cd $GEM_HOME
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.
UPD.
Other locations to look for the residue of the gem:
~/.rvm/gems/ruby-<version>#global
~/.rvm/gems/ruby-<version>
/System/Library/Frameworks/Ruby.framework/
# look for "GEM PATHS" section
gem env
# rbenv paths
~/.rbenv/versions
~/.gem/
UPD2
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.

(2016-May-24)
I solve this problem today.
I was try to learn how to write a gem. and then cause this problem.
My guess is because my gem's name contain whitespace: "hola 1c7"
and gem do not tell you how to solve this prbolem, this is annoying
you should go to:
/usr/local/lib/ruby/gems/2.3.0/specifications
delete that xxx.gemspec
in my case, my gem's name is "hola 1c7"
so I delete "hola 1c7-0.1.2.gemspec"
I think is the space cause problem.
if this not working,
try to search your gems name in /usr/local/lib/ruby/gems/
and delete all the file you can find,
in my case, first I delete
hola 1c7.1.3.2.gem from /usr/local/lib/ruby/gems/2.3.0/cache
so the command is :
/usr/local/lib/ruby/gems/2.3.0/cache$ sudo rm -rf hola\ 1c7-1.3.2.gem
and then
/usr/local/lib/ruby/gems/2.3.0/gems$ sudo rm -rf hola\ 1c7-1.3.2/
My Ruby Version : Ruby 2.3.0
My Linux Version : Ubuntu 16.04 LTS

I couldn't find the files in the reference path, or some of the other suggested paths in this post. Some thing that helped me was to first comment out the error be raised in the version.rb file on line 201. Then use the GEM PATH directory using $ gem env to find the path that had references to the gem. Make sure to remove everything from the doc, cache, and specifications folders. This finally solved my issue.

Related

Struggling to run my ruby cli app

I built a small Cli app in ruby (first ever ruby app), but I'm not able to actually run it.
I started the project off with bundle gem. I have been testing it inside my apps folder by running bundle exec bin/konstruct and everything works fine.
I want to install it locally and test it before I submit it, and so I ran bundle exec rake install after updating all of the info in my gemspec file. It gave successfull output:
konstruct 0.1.1 built to pkg/konstruct-0.1.1.gem.
konstruct (0.1.1) installed.
But when I run the app by entering $ konstruct it gives me an Could not locate Gemfile or .bundle/ directory error, unless I run it from within the root folder of the app.
I have tried to Google but I can't pin the results down to the same issue as I'm having. I've been having this problem even in development (How can I test my Ruby CLI app while still in development?)
I do have a Gemfile and it contains:
source 'https://rubygems.org'
# Specify your gem's dependencies in konstruct.gemspec
gemspec
I don't have a .bundle/ folder though. I'm not sure where/how that folder should be generated. I have run bundle and bundle install many times now.
I have a konstruct.gemspec file which contains: https://github.com/konstruct/konstruct.cli/blob/master/konstruct.gemspec
Most of that file is as it was generated. I just filled it in where I could.
I'm sorry if this is a stupid question, but I am super stuck.
You have the following line in your gemspec:
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
I believe that means if you move your executable file into an exe directory instead of a bin directory, it will work as you expect.
http://guides.rubygems.org/specification-reference/#executables
It turns out I am a first class idiot. Some time ago I added Konstruct in my .path file, which obviously was now overriding the proper konstruct command. Back then what I did din't work, so I just forgot about it.
So the answer to this question: It's not broken. OP is an idiot. :-/

Malformed version number string

I recently installed a gem that was inappropriately named. My installation thinks the the version number is "Epub". The gem is called Simple Epub Creator-0.0.0.gem. I already know what I did wrong (used spaces) but now I need to fix it.
Whenever I run gem with any argument, including uninstall, I get this:
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:200:in `initialize': Malformed version number string Epub (ArgumentError)gem
Followed by a stack trace as long as my arm. Is there an elegant fix to this problem, or is it better to just take the "sledgehammer" approach and nuke the installation, followed by a clean install of ruby and all of the gems I use?
I had a similar issue when I inadvertently did a rake:install on a gem I was building that didn't yet have a version number assigned to it. Running gem, bundle, or rake with any commands resulted in the same error about a malformed version number.
What worked for me was manually deleting all instances of the offending gem in the .rvm folder. In my case, I had a gem named dogecoin- that was missing a version suffix. So cding into my .rvm directory and running find . -path \*doge\* -delete got me back into a functioning state.
My hunch is that version.rb goes through all the gems that you have installed, one of which is your misnamed epub creator.
Maybe you could take a look at the line 200 in the file C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb, see where it's trying to load the misnamed gem, find it and delete it?
I couldn't find the files in the reference path, or some of the other suggested paths in this post. Some thing that helped me was to first comment out the error be raised in the version.rb file on line 201. Then use the GEM PATH directory using $ gem env to find the path that had references to the gem. Make sure to remove everything from the doc, cache, and specifications folders. This finally solved my issue.
I had this same problem today. I was using Ruby installed through homebrew. I found remnants of the bad gem in the following folders. Deleting the references from these two folders seems to have fixed the problem:
/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/doc/
/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/specifications/

bash: /usr/bin/ruby: No such file or directory

I am trying to run a ruby program and I get bash: /usr/bin/ruby: No such file or directory When I navigate to /usr/bin/ruby and ls | grep ruby I get an output with ruby in it. When I try to ./ruby I STILL get bash: ./ruby: No such file or directory. I have tried uninstalling and reinstalling ruby to no avail.
Does anyone have any idea what could be going on? I am really stumped.
Just adding a different possible cause and fix for the same /usr/bin/ruby: No such file or directory error after installing Ruby.
If, unlike the original poster here, you get this same message but on investigating find that there really is nothing at /usr/bin/ruby, try /usr/local/bin/ruby --version: it seems that some installations put the binary in /usr/local/bin/ruby but look for it at /usr/bin/ruby.
This happened to me with ruby version 1.9.3p547 on Centos. If this is what's happened, the easy fix is to create a symlink at /usr/bin/ruby that points to /usr/local/bin/ruby.
Per the comments on the question, your /usr/bin/ruby binary is a symlink to /etc/alternatives/ruby.
lrwxrwxrwx 1 root root 22 Aug 12 20:11 /usr/bin/ruby -> /etc/alternatives/ruby
You should confirm that path exists (run ls -la /etc/alternatives/ruby to check if that path exists) and if it does not, you'll need to reinstall Ruby using your system package manager (e.g., apt-get), download and install Ruby from https://www.ruby-lang.org, or use a tool like RVM.
The better option is use
#!/usr/bin/env ruby
it will always use current selected ruby in the environment, not depending on any tool
I had this error while working on Ruby on rails project and deployment to heroku.
For ruby on rails and heroku
On you editor, find 'bin' folder then in each file remove the ruby number extension leaving 'ruby' only on the commented code.
Thank me later

Fixing "custom_require.rb:36:in `require': no such file to load" errors

I understand that after Ruby 1.9.2, '.' is no longer in your path for security reasons. This seems to be a problem when using certain gems (ones not updated to 1.9 I imagine?), a problem that throws errors like
$HOME/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require': cannot load such file -- rubylog (LoadError)
I've seen and fixed this problem once, by (perhaps naively) changing some requires into require_relatives: https://github.com/mathpunk/MongoDB_Koans/commit/e2f7898347d328450ec121d22f701508f389cc53
Now I'd like to use rubylog, and I'm getting the custom_require error, so I tried the same trick:
https://github.com/mathpunk/rubylog/commit/995e13dccc6a197d280d0783f3fb7fe50deabd02
but this time, I'm just getting the same error. What else can I try?
ETA: All this time, I've been using sudo gem install blah to install gems, and for some reason, for rubylog it's gem install rubylog that does it. (Something to do with RVM?) So now everything works. Thank you.
Your code fails at require 'rubylog' - so it can't find rubylog.rb itself. So just add dir containing rubylog.rb to load path - something like $: << 'rubylog' might help.
Just add the library directory to your LOAD_PATH:
$LOAD_PATH.unshift(File.dirname(__FILE__))
See Understanding Ruby's load paths\
Edit: I assumed you had a rubylog directory wherever your script was running from. If your script can't find rubylog then you need to add that location to your load path:
$LOAD_PATH.unshift('/path/to/rubylog')
Are you sure you have the rubylog libraries? gem install rubylog

Hotcocoa installation path error

I have installed MacRuby 0.6 and then the hotcocoa gem from Github. However, when I try to create a hotcocoa application with eg.
hotcocoa demoapp
I get the error
-bash: /usr/local/bin/hotcocoa: No such file or directory
Typing 'which hotcocoa' results in
/usr/bin/hotcocoa
Other online documentation seems to suggest that this ought to have been installed to /usr/local/bin so I am confused (a) how it ended up here and (b) why it can't be found even though both locations are in my PATH
I installed hotcocoa with:
sudo macgem install hotcocoa
I had previously done a gem install by mistake but I uninstalled that when I realised I should be using macgem instead.
echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec
Any thoughts?
Addendum
As an experiment, I also changed the order of the items in the PATH and it can now find hotocoa. My PATH is now...
/usr/local/git/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/local/bin:/bin:/sbin:/usr/sbin:/usr/libexec
..with /usr/bin listed earlier than /usr/local/bin
Of course this still doesn't explain why it couldn't find it before (all the path elements seem to exist) or why it was installed there.
Thank you for sharing your experience! I've been struggling with the same set of issues and outcomes for a while. Path order was a non-issue in my case.
It appears that for MacRuby 0.7.1 (installed via RVM) with hotcocoa (installed via sudo macgem), the use of 'sudo' is required to avoid potential load errors.
For example:
(1) keying in 'hotcocoa mydemo', displays the 'Could not find RubyGem hotcocoa (>= 0) (Gem::LoadError)' message on my box. Whereas, if I key in 'sudo hotcocoa mydemo', no load error occurs and, Rakefile, config, lib, and resources items can be listed in the 'mydemo' directory.
(2) keying in 'macrake' results in rake aborted: no such file to load -- hotcocoa/application_builder. Whereas, keying in 'sudo macrake' displays the Mydemo window and its 'Hello from HotCocoa' message.
I actually found that installing hotcocoa without the sudo command worked.

Resources