113

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?

0

4 Answers 4

232

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" }
5
  • update from 2017, I couldn't get the GitHub source identifier to work but the :git => ref works fine
    – Amias
    Commented May 31, 2017 at 8:21
  • Maybe its Windows shenanigans, but with RubyInstaller 2.3 on Windows 10, I have this same setup for a gem I have that is unreleased, and I issue the bundle install command, RubyGems says its fetching the git repo, and its installed, but when I do gem list gemname it doesn't show up in my locally installed gems.
    – FilBot3
    Commented Aug 26, 2017 at 21:40
  • nvm, its because I'm expecting bundle install to install as though it were global, or for all rubygems. however, its doing it per project, or sometimes per user. github.com/bundler/bundler/issues/3070#issuecomment-46361014
    – FilBot3
    Commented Aug 26, 2017 at 21:47
  • At least for our environment, the github: identifier gives the transmits data without encryption warning that I'm looking to avoid. Converting to a git: identifier with https might not be enough, as I also have a branch to specify.
    – Pysis
    Commented Dec 7, 2017 at 15:07
  • Regarding installing with github source identifier: 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. - per the link you gave Commented Jan 22, 2018 at 22:00
65
  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
    
6
  • 14
    I needed to change 4. to "rake build" to build the gem. Commented Oct 19, 2010 at 15:18
  • 7
    Instead of 4. I had to use gem build name-of-file.gemspec to build the gem rake build o rake gem did not work for me
    – marimaf
    Commented Nov 17, 2011 at 17:02
  • 5
    Instead of 4 and 5 you can do "rake install"
    – rjurado01
    Commented Mar 12, 2013 at 23:06
  • 3
    Or straight from github: gem 'rails', :github => 'rails', :branch => '5.0-stable' - link: bundler.io/v1.3/git.html
    – Danny
    Commented Jul 5, 2014 at 2:56
  • 1
    For me gem build <gem-name>.gemspec worked. I didn't have rake listed in the Gemfile. So rake build gem threw rake is not part of the bundle. add it to gemfile Commented Dec 16, 2016 at 11:14
5

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
    
3

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'
1
  • If you read till the end of the accepted answer, it says you can use git_source(:github) { |repo| "https://github.com/#{repo}.git" } to solve the https issue.
    – Archonic
    Commented Mar 14, 2023 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.