Install Gem from Github Branch?

RubygemsBranchGithub

Rubygems Problem Overview


In my gemfile I have this:

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

How do I install that as a gem so I can test it?

Rubygems Solutions


Solution 1 - Rubygems

You don't need to build the gem locally. In your gemfile you can specify a github source with a ref, branch or tag.

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'

Then you run bundle install or the short form is just bundle.

Read more about it here: http://bundler.io/man/gemfile.5.html#GIT

Update: There's a github source identifier.

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

However, they warn against using it: 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.

After Bundler 2.0, you can get around the above issue with this statement near the top of the Gemfile:

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

Solution 2 - Rubygems

  1. Clone the Git repository.

     $ git clone git://github.com/odorcicd/authlogic.git
    
  2. Change to the new directory.

     cd authlogic
    
  3. Checkout branch

     $ git checkout -b rails3 remotes/origin/rails3
    
  4. Build the gem.

     $ rake build gem
    
  5. Install the gem.

     $ gem install pkg/gemname-1.23.gem
    

Solution 3 - Rubygems

I have to modify @janic_'s answer to make it work. Hope it will help other ruby noobs like myself.

  1. Clone the Git repository.

     $ git clone git://github.com/odorcicd/authlogic.git
    
  2. Change to the new directory.

     $ cd authlogic
    
  3. Checkout branch

     $ git checkout -b rails3 remotes/origin/rails3
    
  4. Install bundles

     $ bundle install
    
  5. Build the gem.

     $ rake build
    
  6. Install the gem.

     $ gem install pkg/gemname-1.23.gem
    

Solution 4 - Rubygems

To update @Archonic answer, you need to replace the git protocol per the https protocol

fatal: remote error:
  The unauthenticated git protocol on port 9418 is no longer supported.

Therefore, you need to write:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLanceView Question on Stackoverflow
Solution 1 - RubygemsArchonicView Answer on Stackoverflow
Solution 2 - Rubygemsjanic_View Answer on Stackoverflow
Solution 3 - RubygemsHai Feng KaoView Answer on Stackoverflow
Solution 4 - RubygemscharlesdgView Answer on Stackoverflow