Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rubygems rest-client error message

New Ruby user and I am completely addicted, LOVE it...but...I have hit a roadblock right out of the gate Have read plenty on the Ruby basics/theory/etc Working my way through "Bastards" Ruby Lessons and I am getting error message when trying to use "rest-client" gem

I enter:

require "rubygems"
require "rest-client"
res = RestClient.get("http://en.wikipedia.org/wiki")
puts res.code
#=> 200

puts res.body
#=> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
#=> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
#=> <html lang="en" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml">
#=> <head> ...

And get:

LoadError: no such file to load — rest-client

method gem_original_require in custom_require.rb at line 36
method require  in custom_require.rb at line 36
at top level    in gem.rb at line 2
copy output
Program exited with code #1 after 0.06 seconds.

Im sure this is quite basic and feel somewhat embarrassed to ask for help but I have tried every place possible to find a fix

On a Mac OS10

Appreciate your help

like image 492
user1902953 Avatar asked Feb 16 '26 10:02

user1902953


1 Answers

You need to do three things:

1. In your code change require 'rest-client' to require 'rest_client'.

2. make sure the rest-client gem is installed: at the console, go to your project's directory and type

$gem list | grep rest-client

If the gem is installed, the command should return something like rest-client (1.6.7). If that happens, proceed to step #3. If nothing is returned then type:

$gem install rest-client

and wait till the gem is installed.

3. After the gem has been installed, stay on the same command line and run your script from it. If you're running it from within an editor, then start your editor from the same command line, e.g.

$>sublime-text --project mywork.sublime-project &

(assuming sublime-text is in your local bin directory, of course)

like image 166
RedFred Avatar answered Feb 21 '26 14:02

RedFred



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!