0

I'm brand new to ruby. I've written a little script, and at the top I have the following:

require 'rubygems'
require 'net/http'
require 'json'
require 'curb'

But when I attempt to run the script, I get the following:

C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot loa
d such file -- curb (LoadError)
        from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require
'
        from rImDrop.rb:4:in `<main>'

Everything I've found thus far has indicated that require 'rubygems' would fix this issue, but apparently not in my case. Would the next guess be that I have Gems installed incorrectly?

Edit: I should point out that I'm on Windows 7...

When I run gem install curb I get:

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing curb:
        ERROR: Failed to build gem native extension.

        C:/Ruby193/bin/ruby.exe extconf.rb
checking for curl-config... no
checking for main() in -lcurl... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/Ruby193/bin/ruby
        --with-curl-dir
        --without-curl-dir
        --with-curl-include
        --without-curl-include=${curl-dir}/include
        --with-curl-lib
        --without-curl-lib=${curl-dir}/lib
        --with-curllib
        --without-curllib
extconf.rb:23:in `<main>':   Can't find libcurl or curl/curl.h (RuntimeError)

  Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
  options to extconf.


Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/curb-0.8.
0 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/curb-0.8.0/ext/gem_make.ou
t
hodgesmr
  • 2,765
  • 7
  • 30
  • 41
  • 1
    a) Ruby gems is built into Ruby 1.9, so you don't need the `require "rubygems"` line; b) Although you might wish that rubygems automatically downloaded and installed gems that your script requires, it does not. You need to first `gem install curb` from the command line before running your script. – Phrogz Feb 16 '12 at 23:06
  • Thanks for the replies thus far. I tried running gem install curb but got the error in my edit above. – hodgesmr Feb 16 '12 at 23:14
  • 1
    Perhaps that is your new question, then: [how to install curb on Windows](http://stackoverflow.com/questions/1511865/install-ruby-curb-gem-in-windows-xp). – Phrogz Feb 16 '12 at 23:30
  • 1
    See also: http://beginrescue.blogspot.com/2010/07/installing-curb-with-ruby-191-in.html – Phrogz Feb 16 '12 at 23:35

5 Answers5

9

I was getting the same error on ubuntu and

gem install curb

also didn't work. This worked though:

sudo apt-get install libcurl3-dev

jokham
  • 265
  • 4
  • 13
1

Have you installed the gem via "gem install curb" in the shell? The first two, Net::HTTP and JSON, are part of the Ruby 1.9 standard library, so they don't actually use RubyGems at all.

bdon
  • 2,068
  • 17
  • 15
0

Some libraries in Ruby are not pure ruby implementations and depend on system executables and binary files. Curb is one such.

Install curl on your system

e.g. in redhat

yum install curl-devel

sethi
  • 1,869
  • 2
  • 17
  • 27
0

Can you try

gem list

You get a list of installed gems. If curb is missing, it is not installed.

Then you can use (if you are online):

gem install curb

to install it. The gem will be loaded and installed from internet (if there are dependecies, you are asked, if they should be installed.).

knut
  • 27,320
  • 6
  • 84
  • 112
0

The answer lies in those two lines :

checking for curl-config... no
checking for main() in -lcurl... no

It means that the system searched for the curl library but didn't found it.

You need the curl library and its dev files (source code) for the gem to compile.

Yoann Le Touche
  • 1,280
  • 9
  • 13