2010-05-12 141 views
73

在我的Gemfile我有这样的:从Github分支安装Gem?

gem "authlogic", :git => "git://github.com/odorcicd/authlogic.git", :branch => "rails3" 

如何安装,作为一个宝石,所以我可以测试它?

+4

您可能要接受不涉及建设的宝石答案。但我有偏见:) – Archonic 2014-03-10 16:32:32

+1

嗨兰斯,我认为你应该把接受的答案改为@Archonics,因为它很清楚它是最受欢迎的答案。 – 2016-02-26 00:46:43

+1

@Freddy完成!感谢指出:) – 2016-02-26 20:25:52

回答

171

你不需要在本地构建gem。在你的gemfile中你可以指定一个带有ref,branch或者tag的github源文件。

gem 'rails', :git => "git://github.com/rails/rails.git", :ref => "4aded" 
gem 'rails', :git => "git://github.com/rails/rails.git", :branch => "2-3-stable" 
gem 'rails', :git => "git://github.com/rails/rails.git", :tag => "v2.3.5" 

然后运行bundle install或缩写形式只是bundle

了解更多关于在这里:​​http://bundler.io/man/gemfile.5.html#GIT

更新:a github source identifier

gem 'country_select', github: 'stefanpenner/country_select' 

不过,他们警告不要使用它:NOTE: This shorthand should be avoided until Bundler 2.0, since it currently expands to an insecure git:// URL. This allows a man-in-the-middle attacker to compromise your system.

+7

这一个更清洁! – 2013-12-09 05:30:45

+0

从2017年更新,我不能得到GitHub源标识符的工作,但:git => ref工作正常 – Amias 2017-05-31 08:21:15

+0

也许它的Windows shenanans,但与RubyInstaller 2.3在Windows 10上,我有这个相同的设置一个宝石我有是未发布的,我发布'bundle install'命令,RubyGems说它获取git仓库和它的安装,但是当我做'gem list gemname'时,它不会显示在我本地安装的gem中。 – Pred 2017-08-26 21:40:35

59
  1. 克隆Git存储库。

    $ git clone git://github.com/odorcicd/authlogic.git 
    
  2. 更改为新目录。

    cd authlogic 
    
  3. 结帐分支

    $ git checkout -b rails3 remotes/origin/rails3 
    
  4. 建立创业板。

    $ rake build gem 
    
  5. 安装宝石。

    $ gem install pkg/gemname-1.23.gem 
    
+13

我需要改变4.“耙构建”来构建宝石。 – 2010-10-19 15:18:05

+6

而不是4.我不得不使用gem build name-of-file.gemspec来构建gem rake build o rake gem不适合我 – marimaf 2011-11-17 17:02:43

+2

而不是4和5你可以做“rake install” – drinor 2013-03-12 23:06:18

2

假设你是一个捆扎机用户,

$ bundle install 

将安装在你的Gemfile中列出的宝石。 (如果你不是Bundler用户,为什么你有一个Gemfile文件?

+0

如果您打算对这个答案进行回调投票,请首先解释*为什么*您认为它应该被降低投票。没有建设性反馈意见的反对意见对于促进理解没有帮助。谢谢。 – sampablokuper 2016-09-08 17:23:46

2

我要修改@ janic_的答案,使其工作。 希望它能帮助像我这样的其他红宝石小菜鸟。

  1. 克隆Git存储库。

    $ git clone git://github.com/odorcicd/authlogic.git 
    
  2. 更改为新目录。

    $ cd authlogic 
    
  3. 结帐分支

    $ git checkout -b rails3 remotes/origin/rails3 
    
  4. 安装包

    $ bundle install 
    
  5. 建立创业板。

    $ rake build 
    
  6. 安装宝石。

    $ gem install pkg/gemname-1.23.gem