Glenn Jones

Refer to a local gem within a ruby project

Recently I had to fork and adjust a gem. To test whether the integration of this gem within my own project that I was working on was fine, I was looking for a way to use the gem locally, so that I did not have to push it to github or rubygems. Turns out, there is a perfectly easy way to achieve that:

What you do is, you refer to the gem in your Gemfile the regular way, for example:

# Gemfile
source 'https://rubygems.org'

gem 'my-beautiful-gem', '>= 1.0.0'

Then, in your terminal, you assign the gem locally like so:

bundle config local.my-beautiful-gem /Users/glennjones/projects/rubygems/my-beautiful-gem

This ensures that when you bundle, your local gem is referred and loaded. If you then want to reload the gem in your console, you can:

load "/Users/glennjones/projects/rubygems/my-beatiful-gem/lib/my-beautiful-gem/some_class.rb"

When you’re done, you can disable bundler to use the local gem like so:

bundle config --delete local.my-beautiful-gem

Links

Previous article: Fixing gdal-bin error libblas.so.3 cannot open shared object file no such file or directory
Next article: Fixing 'no such middleware to insert before: actiondispatch::static' when precompiling rails assets during docker build
comments powered by Disqus