cannot load such file -- rack/handler/puma
Asked Answered
O

2

7

My setup and the error

I get an error when I start my Sinatra application with rackup and puma. My config.ru file looks like this:

#\ -s puma
require './controller/main.rb'
run Sinatra::Application

So when I now use rackup I get this error:

/home/username/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/handler.rb:76:in `require': cannot load such file -- rack/handler/puma (LoadError)

I use ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]

What I have tried so far

My first thought was that I forgot to install puma, or puma is broken in some way. So I tried:

puma -v
puma version 2.0.1

And I start it directly with ruby:

ruby controller/main.rb 
Puma 2.0.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:4567

And I found this puma issue but I didn't find a real solution.

Finally my questions

  1. Why id this happening?

  2. How can I fix this?

Oocyte answered 20/5, 2013 at 10:6 Comment(4)
Are you using Bundler?Carchemish
yes Bundler version 1.3.4Oocyte
There's two things I'd try first. 1) I'd sandbox the gems so they don't get mixed up with those installed by Rubygems. Remove current bundler stuff with rm -rf .bundle Gemfile.lock bin vendor and run bundle install --binstubs --path vendor. Now all the exes are in the local bin dir and all the gems in the local vendor dir. 2) Run using bundle exec, but since the binstubs command was used you can instead run bin/rackup config.ru. See if that improves things / brings back a different error.Carchemish
okay this work can you explain why? and can you add it as answer so I can accept it. And funny is now I can also use the global rackupOocyte
C
10
  1. Sandbox the gems so they don't get mixed up with those installed by Rubygems.

    Remove current bundler stuff with

    rm -rf .bundle Gemfile.lock bin vendor
    

    and then run

    bundle install --binstubs --path vendor
    

    This installs all gems into vendor/RUBY-ENGINE/VERSION/ and all executables into the bin dir. These are separate from the ones installed via the gem command, which will be system wide.

  2. Run using bundle exec, but since the --binstubs command was used you can instead run

    bin/rackup config.ru
    

By using bundle exec or one of the executables from bin/ you're telling Bundler to only use the gems that it installed. If you installed Puma with Bundler then it will install the Puma handler with the Rack that Bundler installed. But, you'll probably have another version of Rack installed by Rubygems (via gem install rack -r) that doesn't have the handler. To get the right one, sandbox your project's gems and always run stuff from the bin/ directory. If you need the ruby command then use bundle exec ruby… and Bundler will load the correct gems for the project.

I do this with every project now and only install gems via gem install… if I need them system wide. It also makes sure you don't miss any gems out of the Gemfile because you had them already available on your system - no nasty surprises on deployment!

Carchemish answered 20/5, 2013 at 18:48 Comment(0)
P
4

Try to be sure you have

require "rack/handler/puma"

This is one that

Rack::Handler::Puma.run

needs.

Play with this http://gabebw.com/blog/2015/08/10/advanced-rack

Promethium answered 26/10, 2016 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.