sinatra: `require': cannot load such file -- sinatra (LoadError)

I get this error when I try to run a ruby file that contains a minimal ruby code -

require 'sinatra'

get '/' do
  "Hello, World!"
end

Error -

/usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sinatra (LoadError)
    from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from basics.rb:1:in `<main>'

I installed sinatra but I don’t know why I get this error.

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I solved this problem. “gem install sinatra-contrib”

So apparently sinatra-reloader gem was missing. Thanks @iCHAIT

@iCHAIT

  1. Can you post the output of gem env here?
  2. Can you check the output of gem list under ruby 2.3.0? Does it include sinatra gem?
  3. Can you see if adding require 'rubygems' before require 'sinatra' also shows this error?

I solved but installing sinatra and sinatra-contrib on their own. abandoned bundle install

ruby app.rb /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- active_record (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require’ from app.rb:3:in `<main>’

@pravinpande Yeah, I was able to resolve it. So apparently there were 2 versions of ruby installed on my machine, deleted both of them, and did a fresh install of the required version using rvm.

Would recommend using any ruby version manager as pointed out by @kgrz