RubyGems and Bundler
Mirror rubygems.org through the proxy. The examples use the upstream name
rubygems; replace it with the name your operator gave the upstream
(what you need).
| Upstream type | rubygems |
| Package source | https://proxy.example.com/v1/rubygems |
| Clients | Bundler, gem |
| Tested | Bundler 2.5: in CI on every push and in the client lab. gem 3.5: in the client lab. |
Configure
Bundler: a mirror
A mirror redirects the source "https://rubygems.org" of every Gemfile to the
proxy. No Gemfile changes, and Gemfile.lock keeps naming rubygems.org:
bundle config set --global mirror.https://rubygems.org https://proxy.example.com/v1/rubygems
--global writes ~/.bundle/config; --local writes the project’s
.bundle/config.
Bundler: the proxy as the Gemfile’s source
source "https://proxy.example.com/v1/rubygems"
Gemfile.lock then records the proxy’s address (remote:
https://proxy.example.com/v1/rubygems/).
gem
gem sources --add https://proxy.example.com/v1/rubygems/ --remove https://rubygems.org/
Authenticate
Only when the proxy has access control switched on. The proxy takes your proxy token as the password of HTTP Basic authentication, with any user name.
Bundler — credentials for the proxy’s host, kept in Bundler’s configuration and out of the Gemfile and the lock file:
bundle config set --global proxy.example.com "pullthrough:<token>"
gem — in the source URL:
gem sources --add "https://pullthrough:<token>@proxy.example.com/v1/rubygems/" --remove https://rubygems.org/
Trust a private CA
Ruby reads the CA bundle from the environment — for Bundler’s index requests,
for the gem downloads and for gem:
export SSL_CERT_FILE=/etc/ssl/corp-ca.pem
Bundler’s own ssl_ca_cert setting is not enough: it covers the index
requests, and the gem download then fails certificate verification.
Check that it works
bundle install
bundle config list shows the mirror; bundle install --verbose prints every
URL it fetches.
Good to know
- Prefer the mirror. With a mirror,
GemfileandGemfile.lockare the same files with and without the proxy; with the proxy as the Gemfile’s source, both name the proxy’s address. - Gems are verified by the proxy against the SHA-256 the registry’s index declares, including platform-specific gems.
- Publishing does not go through the proxy (
gem push): it is read-only. - With a personal cache link use the mirror
(
bundle config set --global mirror.…), not asourcein theGemfile:GemfileandGemfile.lockthen keep naming rubygems.org, and the link — which works like a password — is not committed.
On the proxy
upstreams:
rubygems:
type: rubygems
url: https://rubygems.org
The compact index (/versions, /info/<gem>) is served live; .gem files are
cached immutably. Details: backends: rubygems.