Be it for performance or for readability, sometimes it’s nice to be able to try out something new quickly without going through a pull request + deployment process. This is possible by modifying the $LOAD_PATH Ruby global variable and requiring the gem manually.
The Ruby global variable
$LOAD_PATH is an alias for
$:, which essentially
contains an array of paths that your app will search through when using the
Obviously the real solution here would be to just put the gem in your Gemfile,
and bundle. However, if you wish to use
benchmark-ips to test the performance
of methods in a Rails console with production data and you don’t have the gem
already bundled, then follow these steps:
- SSH into your target server
gem install benchmark-ips
gem env gemdirto figure out the path where gems are installed. For example:
- Open the Rails console
- Add the gem’s path to the
$LOAD_PATHglobal variable, like so:
$LOAD_PATH << "/usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/benchmark-ips-2.7.2/lib"
- Finally, require the gem’s entry point file. You may need to look into the
gem’s structure to figure out what file you need to require. For example, for
This should let you use almost any gem you need in a Rails production console.