Can't get awesome_print gem to work

Add it to your Gemfile like this:

gem 'awesome_print', :require => 'ap'

I add it to the development group, since that's the only time I need it. The gem doesn't have any other gem dependencies, so I routinely add it to my Gemfile.

Also, add these two lines to your ~/.irbrc file to set ap to be your default pager:

require "awesome_print"
AwesomePrint.irb!

Note that if you use this, however, any projects where awesome_print is not installed in its Gemfile will raise this error when you run rails c:

cannot load such file -- awesome_print

Depending on whatever else you may have in your ~/.irbrc file, this can cause other side effects, such as messing up your prompt. To avoid these, simply add the two lines to the very end of that file.


gem install will put the gem code on your computer, but unless the gem's source code files are on your load path, require won't be able to find them. bundle exec looks at the nearest Gemfile.lock and adds the source code for all the gems listed there to your load path. Rails initialization includes getting Bundler to do this for you.

One solution is to add awesome_print to your Gemfile. However, this will cause your application to have awesome_print as a dependency. Alternatively you can manually add the awesome_print library to your load path after starting up the Rails console and then requiring it:

$ rails c
> $LOAD_PATH << path/to/awesome_print-x.x.x/lib
> require 'awesome_print'
> ap {foo: {bar: {baz: :qux}}}

If you're using RVM, the path is likely to be something like

~/.rvm/rubies/ruby-x.x.x-pxxx@your_gemset_name/gems/awesome_print-x.x.x/lib

install it :

$ gem install awesome_print

include it in you GemFile, if you want :

gem 'awesome_print', :require => 'ap'

add this line to the file ~/.irbrc :

require 'awesome_print'
AwesomePrint.irb!

restart your shell!

just a note: I did this and it didnt work right away, probably need to restart the computer... or I just needed to close all shell tabs and open the terminal again!