【问题标题】:Install Gem from Github Branch?从 Github 分支安装 Gem?
【发布时间】:2011-02-18 21:23:37
【问题描述】:

在我的 gemfile 中有这个:

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

如何将它安装为 gem 以便进行测试?

【问题讨论】:

    标签: rubygems branch github


    【解决方案1】:

    您不需要在本地构建 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.

    在 Bundler 2.0 之后,您可以使用 Gemfile 顶部附近的以下语句来解决上述问题:

    git_source(:github) { |repo| "https://github.com/#{repo}.git" }
    

    【讨论】:

    • 从 2017 年更新,我无法让 GitHub 源标识符工作,但 :git => ref 工作正常
    • 可能是它的 Windows 恶作剧,但在 Windows 10 上使用 RubyInstaller 2.3,我对未发布的 gem 有相同的设置,我发出 bundle install 命令,RubyGems 说它正在获取 git repo,并安装了它,但是当我执行 gem list gemname 时,它不会出现在我本地安装的 gems 中。
    • nvm,这是因为我希望 bundle install 像全局一样安装,或者适用于所有 ruby​​gems。但是,它是按项目执行的,有时是按用户执行的。 github.com/bundler/bundler/issues/3070#issuecomment-46361014
    • 至少对于我们的环境,github: 标识符给出了我希望避免的transmits data without encryption 警告。使用https 转换为git: 标识符可能还不够,因为我还需要指定一个分支。
    • 关于使用 github 源标识符安装: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. - 根据link you gave
    【解决方案2】:
    1. 克隆 Git 存储库。

      $ git clone git://github.com/odorcicd/authlogic.git
      
    2. 切换到新目录。

      cd authlogic
      
    3. 结帐分支

      $ git checkout -b rails3 remotes/origin/rails3
      
    4. 构建 gem。

      $ rake build gem
      
    5. 安装 gem。

      $ gem install pkg/gemname-1.23.gem
      

    【讨论】:

    • 我需要将 4. 更改为“rake build”来构建 gem。
    • 而不是 4。我不得不使用 gem build name-of-file.gemspec 来构建 gem rake build o rake gem did not work for me
    • 你可以使用“rake install”代替 4 和 5
    • 或直接来自 github:gem 'rails', :github => 'rails', :branch => '5.0-stable' - 链接:bundler.io/v1.3/git.html
    • 对我来说gem build <gem-name>.gemspec 工作。我没有在 Gemfile 中列出 rake。所以rake build gem throw rake 不是捆绑包的一部分。将其添加到 gemfile
    【解决方案3】:

    我必须修改@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. 构建 gem。

      $ rake build
      
    6. 安装 gem。

      $ gem install pkg/gemname-1.23.gem
      

    【讨论】:

      猜你喜欢
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 2011-04-20
      • 2011-02-04
      • 2016-07-15
      相关资源
      最近更新 更多