How to Use Bundler with Offline .Gem File

How to use Bundler with offline .gem file?

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

Ruby gem dependencies on offline server

You can download bundler as a .gem file from rubygems and install it on the server with

gem install /path/to/bundler.gem

Then you can pack all gems required for your application into ./vendor/cache directory with

bundle package

If now you deploy your app (along with ./vendor/cache directory) to the server and run

bundle install --local

bundler won't go to rubygems, but instead will install all gems from ./vendor/cache directory.

See bundler-package docs for more information.

Bundler and Heroku with offline gems

Ok I figured out the issue. The Chilkat gem I'm using has OS-specific versions, and the version I unbundled in vendor/gems is for OSx won't work on Heroku/AWS. So even if the path would have worked correctly in Heroku, the gem itself would not.

The problem I face now is because the Chilkat gem is OS-specific, Bundler will generate a Gemfile.lock file specific to the OS on which bundle install was called (OSx in my case). That OSx-specific Gemfile.lock is incompatible with AWS's machines, so Heroku complains that I can't push the code since the Gemfile.lock is inconsistent with what is expected.

This appears to be a known issue with Bundler (How to add Mac-specific gems to bundle on Mac but not on Linux?). I could just avoid committing Gemfile.lock, but we rely on the version dependency management that Gemfile.lock provides. And I don't want to get all the developers on my team to switch to developing on Linux/Unix. Anyway that's a separate issue so I'm closing this for now. Thanks to the people who commented!

Bundler: installing a specific .gem file

I figured it out -- thanks to everyone who responded! :)

The trick was to set up a local gem server (with, uh, "gem server") and change my Gemfile's source to point to http://localhost:8808 instead of http://rubygems.org.

This means bundler will grab all the gems from the current installed gem set (which happens to be fine for my case) and then the compiled libs just work.

Bundler unable to find custom gem

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

Ruby Bundle Install in deployment mode

bundle install will grab the gems from rubygems when run.

bundle package grabs the gems and packages them in vendor/cache.

The package command will copy the .gem files for your gems in the bundle into ./vendor/cache. Afterward, when you run bundle install, Bundler will use the gems in the cache in preference to the ones on rubygems.org.

http://bundler.io/bundle_package.html

gem install XYZ locally (without connection to the internet)

Try,

gem install --local path/to/file.gem

Offline gem dependencies

Have a look at the Bundler tool, especially bundle package could be useful for your use case.



Related Topics



Leave a reply



Submit