【发布时间】:2014-02-10 13:32:07
【问题描述】:
我无法创建私有 gem,将其推送到私有 git 存储库,然后通过 :git 引用在我的 Gemfile 中使用该 gem。
问题是bundler(虽然没有给出错误)似乎没有为我安装 gem。
我发现我可以用任何宝石证明这一点,而不仅仅是我的。所以我将使用 'colorize' gem 来演示它,因为它已经在 github 和 rubygems 上,并且是一个没有依赖关系的简单 gem。这是我使用 gem 的 test.rb 文件:
require 'colorize'
puts 'some blue text'.colorize(:blue)
案例一(可行):
Gemfile如下:
source 'https://rubygems.org'
gem 'colorize'
Bundle 运行愉快,ruby test.rb 输出蓝色文字就好了。
然后我运行gem uninstall colorize 在下一次测试之前进行清理。
案例二(失败):
现在,我将 Gemfile 更改为:
#source 'https://rubygems.org'
gem 'colorize', :git => 'git@github.com:fazibear/colorize.git'
请注意,我注释掉了 rubygems.org 行,以确保我不会意外地从 rubygems 获取 gem。
Bundle 再次运行正常,可以看到从 repo 中获取 gem。到目前为止,一切都很好。但是现在,ruby test.rb 失败了:require cannot load 'colorize'。似乎没有安装 gem,实际上如果我运行gem uninstall colorize 进行清理,它说没有安装 colorize!
那么我在这里做错了什么,或者没有理解?我想从 git repo 安装 gem,而不是 rubygems,因为 gem 是私有 gem。
谢谢, ——格伦
【问题讨论】:
-
运行
bundle exec ./test.rb -
我的回答有帮助吗?