How to use Bundler with offline .gem file?

26,525

Solution 1

I'm using Rails 3.0.3, new to Rails 3 and bundler.

I got this same error with:

gem 'mygem', :path => '/path/to/gem'

Resolved by specifying the version number:

gem 'mygem', '0.0.1', :path => '/path/to/gem'

Using >=0.0.1 for the version reverted to the original error. I can't explain any of this, however.

Quoting JD's helpful commment, from the Gemfile man page: "Similar to the semantics of the :git option, the :path option requires that the directory in question either contains a .gemspec for the gem, or that you specify an explicit version that bundler should use."

Solution 2

Try unpacking the gem and then using the path in your Gemfile.

i.e.

gem unpack my-gem-file.gem /my-rails-app/vendor/gems/

then add a line like so to your Gemfile

gem 'my-gem', '0.0.1', :path => 'vendor/gems/my-gem'

Obviously paths and version numbers will vary. You also might need to make the vendor/gems directory in your app root if it doesn't already exist.

Solution 3

Copy the gem in to vendor/cache directory in your application's root folder.

bundle install --local

This will install the local gem.

Share:
26,525
shedd
Author by

shedd

Updated on June 17, 2020

Comments

  • shedd
    shedd almost 4 years

    For my application, I need to handle encrypted ZIP files. Despite their horrific looking site, it seems that Chilkat's commercial Zip gem is probably the best way to go to implement this.

    Because this is a commercial gem, they don't have it in any of the typical gem sources that Bundler looks at. I was able to install the Linux 64-bit version of the gem under Mac OS X (though I haven't tried to run it yet, so no word yet on if that will actually work). However, I'm first trying to get Bundler to recognize and load the gem from the .gem file that I downloaded.

    Bundler has a path attribute which I've tried to utilize in several ways, but I haven't gotten it to work yet:

    1. I tried using path to point to the .gem file itself, but path expects a directory.
    2. I tried adding .gz to the end of the .gem file and extracting it - I got a directory with a data.tar.gz and metadata.gz inside. path pointed to the extracted directory with these two files didn't work.
    3. I tried extracting the data.tar.gz and metadata.gz and placing the extracted versions inside the directory that I pointed path to. This failed.
    4. I noticed that the gem didn't have a gemspec file - I created one and placed it inside the directory. No luck.

    This is the error that I get:

    $ bundle install
    Fetching source index for http://rubygems.org/
    Fetching source index for http://gems.github.com/
    Could not find gem 'chilkat (>= 0, runtime)' in source at /Users/username/appname/vendor/cache/chilkat-9.1.0-x86_64-linux.
    Source does not contain any versions of 'chilkat (>= 0, runtime)'
    

    Any ideas on how I can get Bundler to see that the gem is indeed in this directory? Any other options other than the path attribute which doesn't seem to be working?

    Many thanks!