How to build a rubygems mirror server?
You can use rubygems-mirror to mirror the gems and Gem in a box to host them.
Install rubygems-mirror:
$ gem install rubygems-mirror
Edit ~/.gem/.mirrorrc
:
---
- from: http://rubygems.org
to: ~/.gem/mirror
Create mirror dir:
$ mkdir ~/.gem/mirror
Start mirroring:
$ gem mirror
Once mirroring finishes edit ~/.gem/mirror/config.ru
:
require "rubygems"
require "geminabox"
Geminabox.data = "./"
run Geminabox
Install Gem in a box:
$ gem install geminabox
Start gem server:
$ cd ~/.gem/mirror
$ rackup
Edit your application's Gemfile
to use your gem server:
source "http://your.servers.ip:9292"
.
Or add it as a local mirror for rubygems.org, so you don't have to change your Gemfile
:
$ bundle config mirror.https://rubygems.org https://localgems.lan
$ bundle config mirror.http://rubygems.org http://localgems.lan
From time to time reindex your mirror:
$ gem generate_index --directory ~/.gem/mirror
how to build a transparent private gem source server
I'd suggest just installing the pre-release bundler, which is several orders of magnitude faster due to major architectural changes. It's not just your connection to rubygems that is slow; it's that painful for all of us ;) gem install bundler --pre
will give you a much faster bundler.
That said, if you really want a loca gem server, try Gem in a box:
https://github.com/cwninja/geminabox
How to specify alternate online mirrors for rubygems
You may try
# list the sources
gem sources -l
# remove a source
gem sources -r https://rubygems.org/
# add an alternative source
gem sources -a https://gems.ruby-china.com/
The above shows my steps to replace the default gem source, because the connection to rubygems.org
is unstable here
Is there a public rubygems.org mirror?
RedHat OpenShift provides own RubyGems mirror: http://mirror.ops.rhcloud.com/mirror/ruby/
Any official mirrors of rubygems.org?
This gem might solve the issue capistrano-strategy-copy-bundled. The usage pretty simple:
config/deploy.rb:
require 'capistrano-strategy-copy-bundled'
set :deploy_via, :copy_bundled
All your gems are packed on local to a tar archive, which is afterwards transferred to the server. However there's one problem, if you want to deploy gems with native extensions (like database drivers, therubyracer etc.) you need to have same architecture and versions of dependent libraries (like glibc) on both machines.
How to use a private gem server hosted gem when building another gem
So this took me awhile to figure out, because the answer is, it's in TWO places. Do this:
- In your gem's Gemfile (yes, Gemfile, not .gemspec), add the source line for your private gem server. If you're also pulling from RubyGems, then it'll look something like this:
source 'http://rubygems.org'
source 'http://myrubygems.mycompany.example.com:8808' # Or wherever your gems are hosted internally (or externally)
gemspec
- Then, in your mynewgem.gemspec put the following:
Gem::Specification.new do |gem|
# [...]
gem.add_dependency 'myoldgem' # the gem hosted at myrubygems.mycompany.example.com:8808
end
The reason this works is probably obvious: Your Gemfile specifies the source for your gems and your .gemspec specifies the dependencies.
Hope this saves someone a few minutes.
Related Topics
In Rails - Is There a Rails Method to Convert Newlines to <Br>
Problems with the Rails Console, Rvm and Readline
How to Reference a Function in Ruby
Couldn't Require Openssl in Ruby
Rails with Ruby-Debugger Throw 'Symbol Not Found: _Ruby_Current_Thread (Loaderror)'
How to Encode Media in Base64 Given Url in Ruby
Best Way to Debug Third-Party Gems in Ruby
Warning: Constant ::Fixnum Is Deprecated When Generating New Model
How to Set Default Ruby Version with Rvm
How to Generate a Human Readable Time Range Using Ruby on Rails
Ruby Read CSV File as Utf-8 And/Or Convert Ascii-8Bit Encoding to Utf-8
Best Way to Highlight Current Page in Rails 3? - Apply a CSS Class to Links Conditionally
Finding Out Current Index in Each Loop (Ruby)
Routing Nested Resources in Rails 3
Is There Equivalent for PHP's Print_R in Ruby/Rails