2

I have a custom gem built as a .gem file that I am trying to reference from my Gemfile. I have placed the .gem file, along with the .gemspec, in the vendor/gems folder. My Gemfile has the following line:

gem 'umlgrader', '1.0.0', :path=>'vendor/gems'

When I run bundle install, it claims to have found the gem but it says it is "using" the gem, rather than "installing" it, even though the gem was not previously installed on my machine. When I try to run my app, I then get a NoMethodError when it tries to call any of the methods in the gem. Why isn't Bundler installing the gem?

I have gotten it to work by unpacking the gem in that directory and then editing the Gemfile as follows:

gem 'umlgrader', '1.0.0', :path=>'vendor/gems/umlgrader-1.0.0'

This solution is less than desirable. I would prefer to be able to install the gem using Bundler since I am trying to deploy the app to Heroku. I have already tried a lot of the solutions I have found online, but I am open to any suggestions.

EDIT: Some of the other pages I have already gone through and tried: Bundler: installing a specific .gem file How to use Bundler with offline .gem file? How do I specify local .gem files in my Gemfile?

I also noticed a lot of people suggest pointing to a Git repository containing the gem. I would rather not do this if I don't have to.

Community
  • 1
  • 1
mattherman
  • 456
  • 4
  • 15
  • Can you please add links to some of the solutions you've tried? This way we can avoid recommending the same things. – xDaevax Sep 17 '14 at 12:39
  • I have read through a lot of the solutions that use :path in the Gemfile and they all claim it will just work, but clearly doesn't. I have also tried using bundle package and putting all of the gems in vendor/cache, which works locally but not when I deploy to Heroku. – mattherman Sep 17 '14 at 13:14

2 Answers2

0

The Bundler documentation is somewhat cryptic on that topic, but that is the intended behaviour of Bundler. In order to use the path option you must unpack the gem at the desired location.

But that should be no problem for Heroku. After all, you are still using Bundler, even if the gem is already unpacked. It's just a step less in the gem installing process...

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
  • It works, it just makes less sense for us. We inherited this project w/ a super weird directory structure where the code that is part of the gem is at the root level, and the web project is within it. So when looking at our repository as a whole, we would be duplicating the code by unpacking it within the web project. – mattherman Sep 17 '14 at 13:36
  • Is there a way to get this to work with the .gem file without using :path? When I don't use path Bundler can't find the gem at all. – mattherman Sep 17 '14 at 13:56
0

Without Docker

You need to clone the repository from github (or other source) to your custom folder. In example below the steps to reproduce how I use custom path to edit gems in a separeted folder:

  1. In this case I use a custom_gems folder inside /bundle: mkdir /bundle/custom_gems.
  2. cd /bundle/custom_gems.
  3. git clone <gem-repository-source>. Is necessary to clone because if you copy from other folder in your computer probably some files are missed.
  4. Set in your Gemfile: gem '<gem-name>', path: '/bundle/custom_gems/<gem-name>'.
  5. Restart you application.

In docker-compose (or Docker)

  1. With docker is little different, in this case I use a /gems folder inside my rails application folder: mkdir <my-app>/gems.
  2. cd <my-app>/gems.
  3. git clone <gem-repository-source>. Is necessary to clone because if you copy from other folder in your computer probably some files are missed.
  4. Set in your Gemfile: gem '<gem-name>', path: '/bundle/custom_gems/<gem-name>'.
  5. If you use docker-compose, you need to bind folders with volumes config, like below:
volumes:
    - ./app/gems:/bundle/custom_gems

With this, your local folder (your machine) copy files inside ./app/gems to /bundle/custom_gems in Docker container.

  1. Restart service.

If you NOT use docker-compose, you need add in Dockerfile some like: ADD ./app/gems /bundle/custom_gems

Jonatas Eduardo
  • 834
  • 9
  • 18