Last Updated: August 16, 2017
· aalvarado

Use pry with Bundler without having it on your Gemfile

Sometimes you don't want to modify your Gemfile just to add a developer dependency for whatever reason.

Most of us use Bundler for managing gems, which restricts your loadpath to only the ones loaded by Bundler.

For example with Sinatra...

So if you try:

$ pry
[1] pry(main)> require 'app'
LoadError: cannot load such file -- 'some/file'

Will fail because your loadpath is empty.

In order to get it working you will need to do the following:

$ pry
[1] pry(main)> require 'bundler'
=> true
[2] pry(main)> Bundler.setup
[3] pry(main)> require 'app'
=> true
[4] pry(main)> Sinatra.constants

Niceness now you can try stuff out on your terminal and everything should work.

you can even put it all on the initial command:

pry -I. -e "require 'bundler';Bundler.setup;require 'app'"


( Irb should work the same too! )


3 Responses
Add your response


That looks pretty cool! Unfortunately, I can't seem to require my application properly though. Are we supposed to replace require 'app' with a require that refers to the name of our app? If so, what's the best place to look for the name of a Rails app and would you mind giving a concrete example?

over 1 year ago ·

Hi EricM.

Yes, usually you will have an app.rb file. The app.rb file will have other requires and it probably loads up the app.

In this intro http://www.sinatrarb.com/intro.html for example, the main file is called myapp.rb, you would use require 'myapp' in my example.

Let me know if this doesn't work for you.

over 1 year ago ·

Thanks Adan! That set me in the right direction. It turns out that for a Rails app, I needed to run require File.expand_path('config/environment') from the root of my project.

over 1 year ago ·