Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the reading order of Rubygem sources

Tags:

ruby

rubygems

gem

I have created a private gem that I have hosted myself. Everything was going well up until someone has created a gem with the same name on rubygems.org. Since rubygems.org has a highest precedence over my gem server url. I am not able to install my gem anymore. I tried to remove the rubygems source:

$ sudo gem source -r http://rubygems.org

and reinstall it so it comes after in the gem source list, but it does not work.

Is there a way to change the lookup order of the gem source?

Note that I don't want to rename my gem.

like image 808
Martinos Avatar asked Apr 19 '13 19:04

Martinos


People also ask

How do I change my gem source?

Managing Gem Sources Sometimes you want to manage your source list–typically when a gem's source changes locations. Ruby Gems gives you several options for managing your gem source list. To list all gem sources, use the -l flag. To remove a gem source, use the r flag followed by the URL of the source to be removed.

Where are gem sources stored?

GitHub is the main Ruby-related content repository. Most often a gem source code will be hosted on GitHub while being published as a fully-fledged gem to RubyGems.org. The Ruby Toolbox is a project that makes it easy to explore open source Ruby projects.

How do I push a gem to RubyGems?

Note that you need an account at RubyGems.org to do this. From the main menu, select Tools | Gem | Push Gem. In the Run tool window, specify your RubyGems credentials. Your gem will be published to RubyGems.org.


2 Answers

You may try the specific_install gem:

gem install specific_install gem specific_install -l <git-url>

Another way is to explicitly state the gem server like so:

gem install mygem -s http://gems.example.com

The best option, in my opinion, is to use Bundler. In your Gemfile add:

gem 'mygem', :git => 'git://git.example.com/myrepo.git'

like image 131
Patrick Oscity Avatar answered Sep 23 '22 08:09

Patrick Oscity


It seems like you can't have an empty gem cache. If you delete the http://rubygems.org cache manually with gem source -r http://rubygems.org, and there are no other sources defined, it automatically gets repopulated. Kind of an annoying misfeature, really.

What did the trick for me was adding my source (an internal server) and then readding rubygems manually.

$ gem source add http://internal-server/
$ gem source
*** CURRENT SOURCES ***

 http://rubygems.org/
 http://internal-server/
$ gem source -r http://rubygems.org/
$ gem source
*** CURRENT SOURCES ***

http://internal-server/
$ gem source -a http://rubygems.org/
$ gem source
*** CURRENT SOURCES ***

http://internal-server/
http://rubygems.org/
like image 21
Mikey T.K. Avatar answered Sep 21 '22 08:09

Mikey T.K.