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

E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-01 06:50
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
4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-06 22:21
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.
E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-06 22:56
if i run: require 'curl'
I get this error, so that means my curl cannot be loaded:
Loaderror: cannot load such file -- curl
4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-06 23:28
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
E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-06 23:49
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 (https://rubygems.org/gems/curb), 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 '<main>': Can't find libcurl or curl/curl.h
<RuntimeError>
Try passing...
4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-07 01:23
> 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:
http://stackoverflow.com/questions/1511865/install...
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
  http://curl.haxx.se/download.html#Win32))
  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

https://rubygems.org/gems/curl 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".
E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-07 19:52
Yeah, at the work I am behind a proxy so make sense what you suggesting.
E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-07 20:35
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
4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-07 23:15
> 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


http://github.com/taf2/curb
>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.
E71f7476af2e339b692dd368a673a45d?d=identicon&s=25 Asim Khan (asim)
on 2014-08-08 16:18
> gem environment

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

I don't see anything under remote resources.
4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-08 22:20
This explains how you can add sources with gem
http://guides.rubygems.org/command-reference/#gem-sources
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.