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

前端 未结 7 1006
野的像风
野的像风 2020-12-22 18:16

I have a couple of gem files which I install via gem install xx.gem. Can I tell Bundler to use them? Or do I have to specify the source path?

相关标签:
7条回答
  • 2020-12-22 18:48

    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 ref
    gem "foreman", git: "git://github.com/pje/foreman.git", ref: "bf648a070c"
    
    # ...or branch
    gem "foreman", git: "git://github.com/pje/foreman.git", branch: "jruby"
    
    # ...or tag
    gem "foreman", git: "git://github.com/pje/foreman.git", tag: "v0.45.0"
    

    (As @JHurrah mentioned in his comment.)

    0 讨论(0)
  • 2020-12-22 18:53

    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 repo
    mkdir repo/gems
    cp *.gem repo/gems
    cd repo
    gem 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.

    0 讨论(0)
  • 2020-12-22 18:56

    You can force bundler to use the gems you deploy using "bundle package" and "bundle install --local"

    On your development machine:

    bundle install
    

    (Installs required gems and makes Gemfile.lock)

    bundle package
    

    (Caches the gems in vendor/cache)

    On the server:

    bundle install --local
    

    (--local means "use the gems from vendor/cache")

    0 讨论(0)
  • 2020-12-22 18:58

    By default Bundler will check your system first and if it can't find a gem it will use the sources specified in your Gemfile.

    0 讨论(0)
  • 2020-12-22 19:07

    Adding .gem to vendor/cache seems to work. No options required in Gemfile.

    0 讨论(0)
  • 2020-12-22 19:10

    I found it easiest to run my own gem server using geminabox

    See these simple instructions.

    0 讨论(0)
提交回复
热议问题