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

Created on 6 Mar 2016  路  15Comments  路  Source: sinatra/sinatra

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]

Most helpful comment

I solved this problem.
"gem install sinatra-contrib"

All 15 comments

Looked at both of them before opening this issue, they didn't prove to be helpful :(

@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?

@kgrz Thanks for responding, here's the info -

$ gem env

RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.0 (2015-01-20 patchlevel 0) [java]
  - INSTALLATION DIRECTORY: /Users/chaitanyagupta/bin/jruby/lib/ruby/gems/shared
  - RUBY EXECUTABLE: /Users/chaitanyagupta/bin/jruby/bin/jruby
  - EXECUTABLE DIRECTORY: /Users/chaitanyagupta/bin/jruby/bin
  - SPEC CACHE DIRECTORY: /Users/chaitanyagupta/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/chaitanyagupta/bin/jruby/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-java-1.7
  - GEM PATHS:
     - /Users/chaitanyagupta/bin/jruby/lib/ruby/gems/shared
     - /Users/chaitanyagupta/.gem/jruby/2.2
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri --env-shebang"
     - "update" => "--no-rdoc --no-ri --env-shebang"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/chaitanyagupta/.local/bin
     - /Library/Frameworks/Python.framework/Versions/2.7/bin
     - /Users/chaitanyagupta/bin/jruby/bin
     - /Users/chaitanyagupta/bin/Sencha/Cmd/5.1.2.52
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /opt/X11/bin
     - /Users/chaitanyagupta/Code/go/bin
$ gem list

*** LOCAL GEMS ***

activesupport (4.2.5.2)
addressable (2.3.8)
axiom-types (0.1.1)
backports (3.6.8)
bcrypt (3.1.11 java)
bcrypt-ruby (3.1.5 java)
buftok (0.2.0)
builder (3.2.2)
bundler (1.11.2)
coercible (1.0.0)
coffee-script (2.2.0)
coffee-script-source (1.10.0)
daemons (1.2.3)
data_objects (0.10.17)
datamapper (1.2.0)
descendants_tracker (0.0.4)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.1)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.2)
dm-sqlite-adapter (1.2.0)
dm-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.2)
dm-validations (1.2.0)
do_jdbc (0.10.17 java)
do_sqlite3 (0.10.17 java)
domain_name (0.5.20160216)
equalizer (0.0.10, 0.0.9)
eventmachine (1.0.9.1 java)
execjs (2.0.2)
fakes3 (0.2.4)
faraday (0.9.2)
fastercsv (1.5.5)
gruff (0.6.0 java)
hike (1.2.3)
http-form_data (1.0.1)
http_parser.rb (0.6.0 java)
i18n (0.7.0)
ice_nine (0.11.1)
jar-dependencies (0.1.2)
jdbc-sqlite3 (3.8.11.2)
jenkins_api_client (1.4.2)
jruby-openssl (0.9.6 java)
json (1.8.3 java, 1.8.0 java)
json_pure (1.8.3)
lolcat (42.1.43)
maven-tools (1.0.7)
memoizable (0.4.2)
minitest (5.8.4, 5.4.1)
mixlib-shellout (2.2.6)
multi_json (1.11.2)
multipart-post (2.0.0)
naught (1.1.0)
nokogiri (1.6.7.2 java)
paint (1.0.1)
power_assert (0.1.4)
rack (1.5.5)
rack-protection (1.5.3)
rack-test (0.6.3)
rake (10.1.0)
rdoc (4.1.0)
rmagick4j (0.3.9 java)
ruby-maven (3.1.1.0.8)
ruby-maven-libs (3.1.1)
rufus-scheduler (2.0.24)
sass (3.4.14, 3.2.19)
shotgun (0.9.1)
simple_oauth (0.3.1)
sinatra (1.4.7)
sprockets (2.10.2)
stringex (1.5.1)
tabula-extractor (0.7.6 java)
terminal-table (1.5.2)
test-unit (3.0.3)
thor (0.18.1)
thread_safe (0.3.5 java, 0.3.4 java)
tilt (1.4.1)
trollop (2.1.2)
tzinfo (1.2.2)
unf (0.1.4 java)
uuidtools (2.1.5)
virtus (1.0.4)

Can you see if adding require 'rubygems' before require 'sinatra' also shows this error?

I tried this, still getting the same error :(

There seems to be a slight mismatch between the ruby versions from your first post and the gem env output. Notice that the gem env output points to a jruby 2.2.0 executable whereas in your first post, the ruby version is MRI 2.3.0.

@kgrz Okay, how can I fix it?

Do you use any ruby version managers? If not, RVM, chruby, rbenv are the most common ones and these will abstract away all these quirks related to setting up correct gem paths and executable paths. Each of those managers also provide ways to install new rubies and keep them updated.

Thanks.

@iCHAIT
Were you able to resolve the issue? I am facing similar issue.
@kgrz I use rbenv version manager, Ruby 2.4.0 and sinatra gem installed.
I am getting below error:
/home/pravin/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- sinatra/reloader (LoadError) from /home/pravin/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from server.rb:3:in `

'

@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

Looks like there is something else. I have only one version but it's giving me the same error.

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

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:inrequire'
from app.rb:3:in `

'

I solved this problem.
"gem install sinatra-contrib"

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

Was this page helpful?
0 / 5 - 0 ratings