简体   繁体   中英

Bundler not installing private gem from git repo

I am having trouble creating a private gem, pushing it to a private git repo, and then USING that gem in my Gemfile via a :git reference.

The problem is that bundler (while giving no error) doesn't seem to install the gem for me.

I found that I can demonstrate this with any gem, not just mine. So I'm going to demonstrate it using the 'colorize' gem since it is already on github and rubygems, and is a simple gem that has no dependencies. Here is my test.rb file that uses the gem:

require 'colorize'
puts 'some blue text'.colorize(:blue)

CASE ONE (this works):

The Gemfile is as follows:

source 'https://rubygems.org'
gem 'colorize'

Bundle runs happily, and ruby test.rb outputs the blue text just fine.

I then run gem uninstall colorize to clean up before the next test.

CASE TWO (fails):

Now, I change the Gemfile to this:

#source 'https://rubygems.org'
gem 'colorize', :git => 'git@github.com:fazibear/colorize.git'

Note that I commented out the rubygems.org line to be sure I don't accidentally get the gem from rubygems.

Bundle again runs just fine, and can be seen to get the gem from the repo. So far so good. But now, ruby test.rb fails: require cannot load 'colorize' . It would seem that the gem didn't get installed, and indeed if I run gem uninstall colorize to clean up, it says that colorize is not installed!

So what am I doing wrong here, or failing to understand? I want to have the gem installed from a git repo, not rubygems, since the gem is a private gem.

Thanks, -- Glenn

Of course the gem isn't installed in second case, that is correct, since it was removed. But when bundler clones a git repo, or to use a path key to create a gem, it doesn't use ruby's gem utility, and to know weither the gem is installed successfully you have just to run, and to see the path of the installed gem:

$ bundle show colorize
/home/user/.rvm/gems/ruby-~.~.~@irb/gems/colorize-~.~.~

If case the gem isn't properly installed, you shell see:

Could not find gem 'colorize'.

And will have to issue bundle install again, and trap errors if any.

Since the bundler doesn't call the gem command, doesn't put the checked out gems from git repos or GitHub into common gem pull, and instead of it creates the gem itself inside its pull, and controls it. You should run your script using the bundler itself:

$ bundle exec ./test.rb

or

$ bundle exec ruby test.rb

It seems to me your ssh connection to github is not setup properly.

Try doing a ssh -T git@github.com as suggested here on github , this will give you an error if things are misconfigured. Follow the steps mentioned in the link and then check again, things should work fine then. FWIW, I tried and was able to install the gem in this fashion.

If you were installing this gem on a server, run this command on the server itself.

An alternative to overcome this (the limitation of configuring ssh keys for each account to use git@github.com url in :git ) is to instead use a https url (Check out this thread ); this however beats all the purpose of using ssh keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM