Ruby + Curl - what do I need to install to write a ruby script that uses curl in it

I have an existing script that is in Ruby and has also cURL commands in
it. I would like to run it.
How can I used ruby with curl? What do I need to download? And how do I
tell Ruby to use curl?

Currently I have Rubygem installed but it doesn’t seem to work. I am on
windows. I downloaded ruby from http://rubyinstaller.org/downloads/,
‘Ruby 2.0.0-p481’. Thanks

I downloaded and installed Ruby 2.0.0-p481 on a virtual machine with
WinXP. When I run “Start Command Prompt with Ruby” and enter ‘gem
install curl’, it works for me.

C:\Documents and Settings\madgaksha> gem install curl
Fetching: awesome_print-1.2.0.gem (100%)
Successfully installed awesome_print-1.2.0
Fetching: unidecoder-1.1.2.gem (100%)
Successfully installed unidecoder-1.1.2
Fetching: curl-0.0.9.gem (100%)
Successfully installed curl-0.0.9
Parsing documentation for awesome_print-1.2.0
Installing ri documentation for awesome_print-1.2.0
Parsing documentation for unidecoder-1.1.2
Installing ri documentation for unidecoder-1.1.2
Parsing documentation for curl-0.0.9
Installing ri documentation for curl-0.0.9
3 gems installed

C:\Documents and Settings\madgaksha> irb
DL is deprecated, please use Fiddle
irb(main):001:0> require ‘curl’
=> true
irb(main):002:0>

External libraries and scripts are loaded by calling “require”. But your
script should be doing that already.

if i run: require ‘curl’
I get this error, so that means my curl cannot be loaded:
Loaderror: cannot load such file – curl

First, you need to install curl for ruby. The easiest way to do so is by
using the program gem, which (should) take(s) care of downloading and
setting it up. gem is a program like ruby or irb, which makes installing
extensions easy for your. Run “Start Command Prompt with Ruby” and type

gem install curl

(without the ‘>’)

and post the output. If everything works out, it should say “[n] gems
installed”

ruby - the interpreter, used to execute scripts
irb - interactive console, used for debugging &c.
gem - package manager, install extensions

I start the command prompt, cd to D:\2-Ruby200 and give this command:

D:\2-Ruby200>gem install curl
‘gem’ is not a recognized as internal or external command…

Cd to bin folder:

D:\2-Ruby200\bin>gem install curl
ERROR: Could not find a valid gem ‘curl’ ()=0) in any repository.

I download curb from here (curb | RubyGems.org | your community gem host), save it
folder (D:\2-Ruby200\lib) then run

D:\2-Ruby200\bin>gem install D:\2-Ruby200\lib\curb-0.8.6.gem
ERROR: Error installing D:\2-Ruby200\lib\curb-0.8.6.gem
ERROR: Failed to uild gem native extension.
D:/2-Ruby200/bin/ruby.exe extconf.rb
checking for curl-config… no
checking for main in -lcurl… no
*** extconfig.rb failed ***
Could not create Makefile due to some reason, prbably lack of necessary
libraries and/or header. Check the mkmf.log file for more details. You
may need configuraiton options.


.

extconf.rb:18:in ‘’: Can’t find libcurl or curl/curl.h

Try passing…

ERROR: Error installing D:\2-Ruby200\lib\curb-0.8.6.gem
ERROR: Failed to uild gem native extension.
D:/2-Ruby200/bin/ruby.exe extconf.rb
checking for curl-config… no
checking for main in -lcurl… no

You will have to download the curl and tell the installation script
where it can find the lib. Take a look here:

To quote the answer there:

Ultimately, in win7 with ruby 1.9.1 the following worked for me
where paths need to be updated to reflect the location (and version)
of your curl version (which can be obtained via
curl - Download))
gem install curb –
–with-curl-lib=“C:/curl/curl-7.21.1-devel-mingw32/bin”
–with-curl-include=“C:/curl/curl-7.21.1-devel-mingw32/include”

‘gem’ is not a recognized as internal or external command…

That’s because Windows cli sucks. But whatever.

I download curb from here

curl | RubyGems.org | your community gem host seems to work out-of-the-box, curb does
not.

ERROR: Could not find a valid gem ‘curl’ ()=0) in any repository.

That is strange. Are you behind a proxy or something? You could also try

gem environment

It should list “http://rubygems.org/” below “Remote Sources”.

Yeah, at the work I am behind a proxy so make sense what you suggesting.

gem install curb –
–with-curl-lib=“D:\2-Ruby200\lib\curl-7.34.0-devel-mingw32\bin”
–with-curl-include=“D:\2-Ruby200\lib\curl-7.34.0-devel-mingw32\include”

I get this error:
Count not find a valid gem ‘curb’ ()= 0) in any repository.

Shouldn’t we say gem install curl

Shouldn’t we say gem install curl

I don’t know if your script requires curl or curb. If it says

require ‘curl’

somewhere, you will need curl, and if it says

require ‘curb’

then you will need curb.

Count not find a valid gem ‘curb’ ()= 0) in any repository.

Then use your local copy D:\2-Ruby200\lib\curb-0.8.6.gem

Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for
the libcurl(3), a fully-featured client-side URL transfer library. cURL and
libcurl live at http://curl.haxx.se/ .

Curb is a work-in-progress, and currently only supports libcurl’s ‘easy’
and ‘multi’ modes.

gem environment

It should list “http://rubygems.org/” below “Remote Sources”.

I don’t see anything under remote resources.

This explains how you can add sources with gem