Alan Coromano
Alan Coromano

Reputation: 26048

Ruby is unable to find a gem or "require" file

A simple Ruby code

require 'rest-client'
server = "http://localhost:3000"
response = RestClient.get(server + "/posts.json")

It throws an exception

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rest-client (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/alex/app1.rb:41:in `<main>'
[Finished in 0.1s with exit code 1]

rest-client gem is installed. And I'm using Ruby 1.9.3 and not 1.9.1. Even more, there is no ruby 1.9.1 installed on my machine.

rvm rubies

   ruby-1.9.2-p290 [ x86_64 ]
   ruby-1.9.2-p320 [ x86_64 ]
=* ruby-1.9.3-p194 [ x86_64 ]

What is that happening and do I get rid of that?

Upvotes: 0

Views: 3539

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176552

Ruby 1.9.3 (and 1.9.2) stores gems in the 1.9.1 folder (I know, this is awkward).

If the project uses Bundler, make sure to list the dependency in the bundle Gemfile. Also, make sure the gem exists in that specific Ruby version.

$ gem list

Maybe you installed it for Ruby 1.9.2 and you are now using 1.9.3.

Upvotes: 1

Related Questions