Search code examples
rubyrubygemsziparchive

How to access 'zip' gem (or 'rubyzip') in Ruby?


I must be missing something totally obvious but I can't seem to get the 'zip' gem to work. I've installed it with rubygems just like I've done with many other gems. Rubygem says it's there but yet when I try to require it, Ruby says it's not there. I'm experiencing the same problem on both Windows and Linux. Here's a Linux session (extra output removed for brevity):

~$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
~$ gem list z
~$ sudo gem install zip 
Successfully installed zip-2.0.2
~$ irb
irb(main):001:0> require 'zip/zip'
LoadError: no such file to load -- zip/zip
        from (irb):1:in `require'
        from (irb):1
        from :0

And a Windows session:

C:\> ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
C:\> gem list z
C:\> gem install zip
Successfully installed zip-2.0.2
C:\> irb
irb(main):001:0> require 'zip/zip'
LoadError: no such file to load -- zip/zip
        from (irb):1:in `require'
        from (irb):1

I'm thinking perhaps there's some underlying dependency that 'zip' needs but I haven't found anything about that in the docs.

I've also had the same lack of success with 'rubyzip' It seems that perhaps 'zip' and 'rubyzip' are forks?

Any ideas? Or if there's a better gem out there for archiving, I'd love to hear about it. The choice of zip archiving gems is confusing. The gem 'Zippy' looks good but it requires 'zip' so I'm still stuck.


Solution

  • Try this.

    gem install rubyzip2
    

    then

    irb> require 'rubygems'
    #=>  true
    irb> require 'zip/zip'
    #=>  true
    # you can also require 'zip/zipfilesystem'