Malformed version number string - ruby

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/

Related

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 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.

gem install doesn't update .so files if changed?

I'm trying to create a gem which includes a C extension. I'm using the standard Gem::PackageTask to make the gem.
When I install the gem it builds the .so file properly and installs it in three locations:
/home/me/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/nmatrix-atlas-0.1.0/nmatrix_atlas.so
/home/me/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/nmatrix-atlas-0.1.0/lib/nmatrix_atlas.so
/home/me/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/nmatrix-atlas-0.1.0/ext/nmatrix_atlas/nmatrix_atlas.so
I'm curious as to why it makes three copies of this. But anyway, the first one is the one that actually gets loaded when i do require 'whatever'. The problem is that when I make a change to the code, then repackage the gem, then run gem install again, the new code gets compiled into a new .so and the latter two .so's get replaced with the new, but the first one doesn't get updated. So ruby still sees the old code. I have to do gem uninstall followed by gem install to get it to update.
Is this a bug in rubygems? Or is it the expected behavior? Or am I doing something else wrong?
EDIT: For anyone who is curious, I filed a bug on rubygems. No response yet.

Finding short path to Foundation

Can someone explain why the short path in my config.rb file isn't compiling:
require 'zurb-foundation' # it fails
But when I specify the full path it does:
require "/Users/lukashillebrand/.rvm/gems/ruby-1.9.3-p327/gems/zurb-foundation-4.2.2/lib/zurb-foundation.rb";
I'm using CodeKit to compile and Foundation 4
The reason is that CodeKit is apparently using the system ruby, and so the relative path is looking there. Your full path is pointing to an rvm version, which is installed elsewhere.
The quick fix is temporarily switch rvm to the system ruby & gemset, and install zurb-foundation there:
$ rvm system
$ sudo gem install zurb-foundation
I do not know zurb, just Ruby as a language/platform, and I think that if that first 'require' throws, then most probably some paths are not set up properly in your server environment.
Is Zurb distributed as a gem? Are other gems found well and are require'able by your code? If not, or if you don't know, try adding
require "rubygems"
as the very first line of your code (well, after some initial shebang and other comments). It should normally be invoked by the framework, somewhere before your file, but as I already said, I don't know Zurb. Maybe it simply does not do that for performance reasons.
Also, run some simple file in the same environment and inspect the $: variable, it should show you the paths that are searched for modules. If in very deadline'y times, you can even temporarily push a new path to it (just replace the '.' with your target path), but it'd be best left as a last resort. Your zurb module seems to sit in Gems, so it should be found automatically.

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

Ruby cannot find sqlite3 driver on windows

I am trying to set up Ruby on Rails on windows. I am using the Flash Rails distribution that looks pretty good, but there is an issue with sqlite3. I found the threads telling me to install version 1.2.3, which installed fine. I'm using ruby 1.9.0, and every time I try and run a script (e.g. rake db:create) that uses the database I get an error message "no driver for sqlite3 found".
This apparently is a missing sqlite3.dll, but I have the dll in my %PATH%, and I have also tried copying it into the directory where I am running the script from, the directory where the sqlite3 ruby code lives.
Does anyone have any ideas? If possible I want all teh ruby stuff to be self contained so I can use it from a pen drive.
EDIT: To clarify, I already used gem install to install the ruby-sqlite3 gem - it is just non functional as it cannot find the sqlite3.dll (even though it is actually present in a directory on my %PATH%)
EDIT PART 2: After doing some more digging, the problem appears that ruby will not load the sqlite3_api.dll. I have copied it all over my filesystem, I just get a failure to read file. Other dll libraries in the same directory (e.g. zlib.dll) work fine!
I tried installing the dlls into system32, and that did not work either.
The problem put simply is that sqlite3-ruby 1.2.3 is not compatible with ruby 1.9. This is caused because ruby 1.9 does not use .dll files for c libraries it uses .so files instead. Additionally, since sqlite3_api.dll is written against msvcrt-ruby18.dll. This means that it specifically only will support ruby 1.8.*.
The good news is that there is a fat binary version that will support both ruby 1.8 and ruby 1.9. Uninstalling all former versions of sqlite3-ruby and then installing this one. (You may have to manually delete some versions the gem after uninstalling.) in order to install it use
install sqlite3-ruby --source http://gems.rubyinstaller.org
for more information see this website
Try installing the sqlite3-ruby gem:
gem install sqlite3-ruby
Something similar happened to me recently so I thought I'd update my answer.
For reference there's a sqlite3_api.dll file located in the gem's lib directory. Also the sqlite3.dll file needs to be reachable on the path. They are different files, the first is required by the gem to interface Ruby to C code, while the second contains the actual Sqlite implementation.
It's best to get the second file from the sqlite website and extract it to the Ruby\bin directory (as you shouldn't manually put DLL's into the windows or windows\system directories any more).
So for reference "sqlite3_api.dll" needs to be in:
Ruby\lib\ruby\gems\1.8\gems\sqlite3-ruby-1.2.3-x86-mswin32\lib
and "sqlite3.dll" needs to be on the path, possibly in:
Ruby\bin
As for the "driver not found" problem I would suggest trying the easy things first and making sure gems is installed correctly, up to date, and that the RUBYLIB and PATH environment variables are set appropriately. (System restart may be required to propagate the changes fully.)
Re this link
Download sqlitedll-3_6_10.zip and extract into ruby/bin!
Try going to sqlite.org download page and get the zipped up dll. Then put that in your c:\windows\system32 folder, that should allow Ruby to find it.
Restart your machine after running install sqlite3-ruby
To clarify, which gem are you using? sqlite-ruby or sqlite3-ruby?
They're part of the same project, but different releases. The key is that sqlite3 appears to have driver code included.
I assume you're attempting to use the first, since it's giving me the same error. If so, try switching.
Also.. How literal do you mean by this?
but I have the dll in my %PATH%
PATH=...;C:\sqlite\sqlite3.dll
PATH=...;C:\sqlite
The first will attempt to find C:\sqlite\sqlite3.dll\sqlite3.dll, AFAIK.
I use Ruby 1.8.7 (works with 1.9.1 too)
OS is WindowsXP SP3
Go to
http://www.sqlite.org/download.html
and Download file
sqlitedll-3_7_0_1.zip (265.19 KiB)
and unzip then we will get
sqlite3.dll
Copy sqlite3.dll to your bin folder
as C:\Ruby191\bin or C:\Ruby187\bin
then it works

Resources