How to install gem from GitHub source?
Asked Answered
S

10

472

I would like to install gem from the latest GitHub source.

How do I do this?

Sib answered 5/4, 2010 at 7:26 Comment(0)
A
347

In case you are using bundler, you need to add something like this to your Gemfile:

gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git'

And in case there is .gemspec file, it should be able to fetch and install the gem when running bundle install.

UPD. As indicated in comments, for Bundler to function properly you also need to add the following to config.ru:

require "bundler" 
Bundler.setup(:default)
Abbyabbye answered 14/9, 2011 at 19:13 Comment(7)
I also needed to add the following (added to my config.ru): require "bundler" Bundler.setup(:default) See bundler docs for more detailsGula
Additionally one can specify ref, branch or tag options for example gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :branch => 'yourbranch'Hylton
there's also: gem 'redcarpet', github: 'tanoku/redcarpet'. akash.im/2012/06/05/bundler-new-github-option.htmlDissimilate
@AmitPatel Thank you so so so much !!! :branch => 'yourbranch', your this line has solved a great problem for me just now. So much Grateful to you.Photolysis
@gryzzly, how to specify tag for git?Guidry
@Guidry gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :tag => 'v2.3.5' <- the :tag => '' partAbbyabbye
In case you get the following warning replacing git:// with https:// solved it: The git source git://... uses the git protocol, which transmits data without encryption. Disable this warning with bundle config set --local git.allow_insecure true, or switch to the https protocol to keep your data secure.Tolkan
E
416

That depends on the project in question. Some projects have a *.gemspec file in their root directory. In that case, it would be:

gem build GEMNAME.gemspec
gem install gemname-version.gem

Other projects have a rake task, called gem or build or something like that. In that case you have to invoke rake <taskname>, but that depends on the project.

In both cases you have to download the source.

Edme answered 5/4, 2010 at 7:46 Comment(5)
Just a tip to let people know what it's really happening. The gemname-version.gem file is created when invoking gem buildDwinnell
Where does gem install gemname-version.gem command installs the git gem locally? I cannot find anywhere in my local machine an engine gem installed this way. Where does bundler hides it?Leontine
I think the gem install gemname-version.gem line should be gem install --local gemname-version.gemMount
@Leontine - gem which gemname should tell you where a specific gem is, does that not work for you?Dasteel
Hi, I have only Rakefile and I have no clue how to install it. Any help?Revoke
A
347

In case you are using bundler, you need to add something like this to your Gemfile:

gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git'

And in case there is .gemspec file, it should be able to fetch and install the gem when running bundle install.

UPD. As indicated in comments, for Bundler to function properly you also need to add the following to config.ru:

require "bundler" 
Bundler.setup(:default)
Abbyabbye answered 14/9, 2011 at 19:13 Comment(7)
I also needed to add the following (added to my config.ru): require "bundler" Bundler.setup(:default) See bundler docs for more detailsGula
Additionally one can specify ref, branch or tag options for example gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :branch => 'yourbranch'Hylton
there's also: gem 'redcarpet', github: 'tanoku/redcarpet'. akash.im/2012/06/05/bundler-new-github-option.htmlDissimilate
@AmitPatel Thank you so so so much !!! :branch => 'yourbranch', your this line has solved a great problem for me just now. So much Grateful to you.Photolysis
@gryzzly, how to specify tag for git?Guidry
@Guidry gem 'redcarpet', :git => 'git://github.com/tanoku/redcarpet.git', :tag => 'v2.3.5' <- the :tag => '' partAbbyabbye
In case you get the following warning replacing git:// with https:// solved it: The git source git://... uses the git protocol, which transmits data without encryption. Disable this warning with bundle config set --local git.allow_insecure true, or switch to the https protocol to keep your data secure.Tolkan
M
284

Try the specific_install gem it allows you you to install a gem from its github repository (like 'edge'), or from an arbitrary URL. Very usefull for forking gems and hacking on them on multiple machines and such.

gem install specific_install
gem specific_install -l <url to a github gem>

e.g.

gem specific_install https://github.com/githubsvnclone/rdoc.git 
Moneymaker answered 1/8, 2012 at 21:4 Comment(5)
could you add more explanation on the specific_install gem?Viva
This is exactly what I was looking for, similar to Python's pip git support. gem specific_install -l <url to project on github> worked like a charm!Ignatius
ERROR: While executing gem ... (NoMethodError) undefined method 'build' for Gem::Package:Module Sounds very cool but I won't be looking into it further. Just wanted to post that it didn't work for me in case someone else is about to give it a whirl based on SO recommendation.Windsucking
@Windsucking +1 to your comment. I created a separate question about that error here: #27046374Oconnor
Is there a way to specify branch to use? - Edit responding to myself, from the doc: "$ gem specific_install github.com/githubsvnclone/rdoc.git edge" or "$ gem specific_install -l github.com/githubsvnclone/rdoc.git -b edge"Unmoral
C
43

Bundler allows you to use gems directly from git repositories. In your Gemfile:

# Use the http(s), ssh, or git protocol
gem 'foo', git: 'https://github.com/dideler/foo.git'
gem 'foo', git: '[email protected]:dideler/foo.git'
gem 'foo', git: 'git://github.com/dideler/foo.git'

# Specify a tag, ref, or branch to use
gem 'foo', git: '[email protected]:dideler/foo.git', tag: 'v2.1.0'
gem 'foo', git: '[email protected]:dideler/foo.git', ref: '4aded'
gem 'foo', git: '[email protected]:dideler/foo.git', branch: 'development'

# Shorthand for public repos on GitHub (supports all the :git options)
gem 'foo', github: 'dideler/foo'

For more info, see https://bundler.io/v2.0/guides/git.html

Constabulary answered 10/2, 2015 at 21:40 Comment(1)
Please note that you might get in trouble if you use this approach with passenger and apache / ngix. When running bundle, such git-gem- dependencies will not be installed globally but in the current user's home directory instead. Passenger will run ruby as your web-server's user (e.g. www-data) which has no access to this directory and therefore this "git-gem" won't be loaded. You will get an error ... is not yet checked out. Run bundle install first.Mylander
C
16

OBSOLETE (see comments)

If the project is from github, and contained in the list on http://gems.github.com/list.html, then you can just add the github repo to the gems sources to install it :

$ gem sources -a http://gems.github.com
$ sudo gem install username-projectname
Calumniate answered 22/6, 2011 at 20:3 Comment(2)
o rly? i just now did this and it DID work... go to gems.github.com before adding it to yr sources i guess? (but don't use sudo)Basketwork
@esharp, they host the ones they built, but they don't build them anymore. If the gem got updated since 2009, a gems.github.com copy will be obsolete.Test
W
12

If you are getting your gems from a public GitHub repository, you can use the shorthand

gem 'nokogiri', github: 'tenderlove/nokogiri'
Wassail answered 6/9, 2014 at 4:53 Comment(0)
V
4

Also you can do gem install username-projectname -s http://gems.github.com

Varela answered 19/10, 2012 at 21:13 Comment(2)
Obsolete, see the other answer's comments.Infarct
Still helped me for an issue with an old code base. Yes its 2013 and i am working on a rails 2.3.4 project.Embark
H
3

If you install using bundler as suggested by gryzzly and the gem creates a binary then make sure you run it with bundle exec mygembinary as the gem is stored in a bundler directory which is not visible on the normal gem path.

Happening answered 15/3, 2012 at 12:9 Comment(0)
K
3

In your Gemfile, add the following:

gem 'example', :git => 'git://github.com/example.git'

You can also add ref, branch and tag options,

For example if you want to download from a particular branch:

gem 'example', :git => "git://github.com/example.git", :branch => "my-branch"

Then run:

bundle install
Kneehigh answered 10/5, 2017 at 1:49 Comment(0)
D
2

On a fresh Linux machine you also need to install git. Bundle uses it behind the scenes.

Dalliance answered 30/8, 2012 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.