Changing the reading order of Rubygem sources

2019-04-08 18:33发布

问题:

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.

回答1:

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'



回答2:

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/