1

I have a private gem, called X, whose source code is hosted on Github. If I want to use X in a project, I add gem 'X', :git => 'git@github.com:my-org/x.git' to my project's Gemfile. I can then launch irb and type require 'bundler/setup' and then require 'x'. The functionality of X is available.

Now, I have a different private gem, called Y, whose source code is also hosted on Github. I want to use X from within Y.

How can I accomplish this?

jerzy
  • 2,364
  • 4
  • 20
  • 24

1 Answers1

-1

If your ssh key is configured on github this will work:

gem 'gem', :git => 'git@github.com:user/gem.git', :ref => 'ref'

You can test it by running ssh -t git@github.com

Other options are using your username and password and basic auth:

gem 'gem', git: 'https://user:password@github.com/user/gem.git'

Or more safely using environment variables to protect your password:

gem 'gem', :git => "https://#{ENV['gem_username']}:#{ENV['gem_password']}@github.com/gem.git"

This last example is also a good idea if you're using a CI server to deploy your project.

Raphael
  • 1,760
  • 1
  • 12
  • 21
  • Assuming you are suggesting these lines go in the gem's `Gemfile`, this does not work. When running `gem build y.gemspec` you will recieve an error that states: `The git source git@github.com:my-org/x.git is not yet checked out. Please run \`bundle install\` before trying to start your application`. – jerzy Feb 09 '17 at 21:35
  • Yes, you need to run `bundle install` before building – Raphael Feb 10 '17 at 14:25