How to Host Gem in Github and Use It

how to host gem in Github and use it?

If you want to use your own gem, you can specify that using the git option in your Gemfile:

gem 'test_gem', git: 'git@github.com:praveenitmec/testgem.git', branch: 'master'

And, then run:

bundle install

This is the correct way of using a private gem that you don't want to share with anyone else outside your company.

But, if you want to share your gem publicly, you can publish the gem and use that like any other gem in your Gemfile. To know how to publish a gem, tehre are many articles online that you can search for. Here is one of them.

Update

If you want to use the local version of the gem, then you have to specify using the path option this way:

gem 'test_gem', path: 'path_to_your_test_gem'

How to install gem from GitHub source?

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)

Creating and uploading gem on github

Best practice way of doing this nowadays is to use Bundler. There's a guide here to show you how...

http://asciicasts.com/episodes/245-new-gem-with-bundler

Should I host gems in GitHub or RubyGems?

Are there any reasons for hosting my
gems on GitHub and not RubyGems?

1) GitHub has stopped building new gems, but is continuing to host gems that were previously placed on the site.) The answer is, you can't. (

The GitHub gem building process was always kind of hacky and wasn't 100% solid. (check out the "gem issues" support queue on their help site sometime). GitHub's about git hosting, Gemcutter is about gem hosting. Enough said. :)

Does RubyGems have private
repositories like GitHub?

Nope, not yet. We've considered it, but offering private gem servers/subdomains seems to conflict with the open nature of the site. If you need a gem server for your code that is internal, just use gem server or geminabox.

I've read that jeweler is nice for
creating gem skeleton. On their
webpage it sounds like it uploads
these gems to GitHub and not RubyGems.
But didn't GitHub removed the Gem
support?

Jeweler's still a great way to get started creating a gem. I'm pretty sure rake release with Jeweler's rake tasks installed will just do a gem push now, so it will publish to RubyGems.org.

This railscast
http://media.railscasts.com/videos/183_gemcutter_and_jeweler.mov
shows us how to use gemcutter to
manage gems. But Gemcutter.org is now
RubyGems.org right? But still a gem
called gemcutter is available? Is this
managing gems for us but in
RubyGems.org now?

Yep, gemcutter.org, rubygems.org, and gems.rubyforge.org all redirect to the same place. The gem push and gem owner commands are now in RubyGems proper, so you don't need the gemcutter gem to publish anymore. The gemcutter gem is still available and contains yet to be merged in commands, such as gem yank and gem webhook.

The full story on all of the transition changes is here.

Force bundle install to use https:// instead of git:// for GitHub-based gems

Git provides URL rewriting functionality using the url..insteadOf configuration option.

So to make all connections to github.com use https:// rather than git://

git config --global url."https://github.com".insteadOf git://github.com

The --global switch sets the config option for all git operations by the current user, so there are times where it may be too intrusive. But it does avoid changing the git config in the current project.

Creating a gem server, which I can release gems to

This is fairly simple if you have a server you can host your private gems on. Setup a subdomain, something like gems.companyname.com and setup a virtual host to host your domain. You'd point that virtual host to a folder like you would any website and setup the gem server from there.

Example:

mkdir /var/www/gemserver
mkdir /var/www/gemserver/gems
cp private-gem-0.1.0.gem /var/www/gemserver/gems
cd /var/www/gemserver
gem generate_index

/var/www/gemserver would be the root directory. Lastly all you'd need to do is add a new source to your Gemfile

source 'http://rubygems.org'
source 'http://gems.companyname.com'

So anyone that knows about your custom domain can get access to the gems. The only pain is every time you rebuild your gem you need to run the generate_index command again after you upload your gem to the gems folder.



Related Topics



Leave a reply



Submit