tags:

views:

126

answers:

4

I am on Ubuntu10

sudo apt-get install ruby1.9.1-full

then download sources of rubygem 1.3.7 and install it

sudo ruby setup.rb

then, for example, install sinatra

sudo gem install sinatra

Finally open irb and type

require "rubygems"
require "sinatra"

and get error

LoadError: no such file to load -- sinatra
    from (irb):2:in `require'
    from (irb):2
    from /usr/bin/irb:12:in `<main>'
A: 

I usually hit this error when I forget:

require 'rubygems'

It'd be helpful if you provided the actual code sample, though, what gem you want to require, and what Ruby version you're using if this doesn't solve the problem.

Matchu
as of 1.9 you don't need to require rubygems
Isaac Cambron
@Isaac Cambron - that's true, which is why I asked for more details. The OP has since provided them. The answer clearly isn't relevant to this particular user at this point, but I'll leave it up for reference :)
Matchu
+1  A: 

This was before here on SO quite a few times. Problem is that you probably have two versions of ruby. The one is installing the gem and the other one is trying to use it. Do this in terminal:

$ which -a ruby

Or this:

$ which -a gem

to see if you have more than one version of ruby/gem installed. If so - remove one version (via $ rm or package manager of your system).

Eimantas
i have one ruby and one gem :)
lublushokolad
+1  A: 

Execute

sudo gem install sinatra --verbose

and note the path where the gem is getting installed.

Then try this in irb

puts $LOAD_PATH

and make sure that gem is installed in one of the directories in $LOAD_PATH

And ideally just start using http://rvm.beginrescueend.com/

dolzenko
+1 I think it's easier to adjust the set of directories in the load path (as in my answer), but clearly this will work too.
Isaac Cambron
rvm confused me
lublushokolad
A: 

I had exactly this problem. The problem is that gem and ruby disagree about where the gems live. Compare these:

ruby -e "puts Gem.path"

gem env

gem which sinatra

If you're like my setup, you'll notice that there's an entry in gem env's paths that isn't in Gem.path, and that's exactly where sinatra will claim to be. In my case, I had to add

export GEM_HOME=/usr/lib/ruby/gems/1.9.1

to my .profile. Then everyone was happy.

Isaac Cambron