Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Bundler with offline .gem file?

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!

like image 507
shedd Avatar asked Nov 24 '10 22:11

shedd


People also ask

How do I run a .gemfile file?

run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.

How do I install bundles to install missing gems?

In the invoked popup, start typing bundler, select bundle install and press Enter . Select Tools | Bundler | Install from the main menu. Open the Gemfile, place the caret at any highlighted gem missing in the project SDK and press Alt+Enter . Select Install missing gems using 'bundler' and press Enter .


2 Answers

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."

like image 124
aceofspades Avatar answered Oct 21 '22 11:10

aceofspades


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.

like image 39
semanticart Avatar answered Oct 21 '22 11:10

semanticart