How do I specify local .gem files in my Gemfile? How do I specify local .gem files in my Gemfile? ruby ruby

How do I specify local .gem files in my Gemfile?


This isn't strictly an answer to your question about installing .gem packages, but you can specify all kinds of locations on a gem-by-gem basis by editing your Gemfile.

Specifying a :path attribute will install the gem from that path on your local machine.

gem "foreman", path: "/Users/pje/my_foreman_fork"

Alternately, specifying a :git attribute will install the gem from a remote git repository.

gem "foreman", git: "git://github.com/pje/foreman.git"# ...or at a specific SHA-1 refgem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"# ...or branchgem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"# ...or taggem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"

(As @JHurrah mentioned in his comment.)


Seems bundler can't use .gem files out of the box. Pointing the :path to a directory containing .gem files doesn't work. Some people suggested to setup a local gem server (geminabox, stickler) for that purpose.

However, what I found to be much simpler is to use a local gem "server" from file system:Just put your .gem files in a local directory, then use "gem generate_index" to make it a Gem repository

mkdir repomkdir repo/gemscp *.gem repo/gemscd repogem generate_index

Finally point bundler to this location by adding the following line to your Gemfile

source "file://path/to/repo"

If you update the gems in the repository, make sure to regenerate the index.


I would unpack your gem in the application vendor folder

gem unpack your.gem --target /path_to_app/vendor/gems/

Then add the path on the Gemfile to link unpacked gem.

gem 'your', '2.0.1', :path => 'vendor/gems/your'