4

I'm working on my local machine. If I use a Sinatra app I have no problem adding this line to myapp.rb

require 'sinatra'

When I go to the console and I run

irb -r myapp.rb

I get this error

gem_original_require': no such file to load -- sinatra (LoadError)

I understand that either my IRB or Ruby path is not looking right. I am using (Simple Ruby Version Management: rbenv) to manage the Ruby environment not too sure if this affects things? I ran the gem env and I got this.

RubyGems Environment:  
  - RUBYGEMS VERSION: 1.8.10  
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1]  
  - INSTALLATION DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1  
  - RUBY EXECUTABLE: /Users/Air/.rbenv/versions/1.9.2-p290/bin/ruby  
  - EXECUTABLE DIRECTORY: /Users/Air/.rbenv/versions/1.9.2-p290/bin  
  - RUBYGEMS PLATFORMS:  
    - ruby  
    - x86_64-darwin-11  
  - GEM PATHS:  
     - /Users/Air/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1  
     - /Users/Air/.gem/ruby/1.9.1  
  - GEM CONFIGURATION:  
     - :update_sources => true  
     - :verbose => true  
     - :benchmark => false  
     - :backtrace => false  
     - :bulk_threshold => 1000  
  - REMOTE SOURCES:  
     - http://rubygems.org/  
alenm
  • 1,013
  • 3
  • 15
  • 34
  • 1
    Did you add `require 'rubygems'` before you require sinatra in your `myapp.rb` file? – Casper Nov 27 '11 at 06:17
  • @Casper He's using 1.9.2, so there should be no need to require rubygems. – bloudermilk Nov 27 '11 at 10:57
  • I did try `require rubygems` but that doesn't help as @bloudermilk stated I'm using Ruby 1.9.2. I keep thinking it has something to do with the ruby management tool rbenv. I don't know. I can't figure out how to troubleshoot this. – alenm Nov 27 '11 at 15:49
  • The command `irb` just a console, i don't think that as likes the `ruby -r`, though the help document of irb describes like this. You could try this `ruby -r myapp.rb`, and ensure the Sinatra in the list of gem (see `gem list`) – coolesting Nov 28 '11 at 03:46
  • I'm working on a sinatra app and I just want to interact with the console. I found a tip that said `irb -r myapp.rb` would be the way to do so. – alenm Nov 28 '11 at 06:28
  • Looks like the solution was provided here. My irb was loading the incorrect ruby/path. By changing the shebang line at the top of the irb file to the correct path it solved the problem http://stackoverflow.com/questions/8364833/irb-loading-wrong-ruby-and-gem-path-using-rbenv – alenm Dec 03 '11 at 15:02

2 Answers2

2

In my case I was using rvm. Even though I configured and .rvmrc file and assured I was using a proper gemset with sinatra installed, I kept having the same error.

Then I tried installing sinatra in my native ruby version:

gem install sinatra

I had to install the sqlite adapter as well for the sinatra app I was trying to run:

gem install sqlite3

Finally I got to run the scanty blog (https://github.com/rodrigomes/scanty) with:

ruby main.rb

It worked but I don't think it is the best solution.

ajtrichards
  • 29,723
  • 13
  • 94
  • 101
2

Try:

irb -r ./myapp.rb

If you're using a config.ru file, that path should be reflected there as well.

shanethehat
  • 15,460
  • 11
  • 57
  • 87
jbarr
  • 21
  • 2