Ruby 2.5.1安装bundler遇Gem::RemoteFetcher::FetchError,求彻底解决方案
Hey there, let's break down why you ran into that 403 Forbidden error and how to fix it for good.
Root Cause
The core issue here is that the http://gems.github.com source you're hitting is long deprecated and no longer functional. GitHub shut down its dedicated Gem hosting service years ago, migrating all official Gem hosting to the standard RubyGems registry at https://rubygems.org/.
Your Ruby 2.5.1 installation (which is a somewhat older version) likely still had this outdated source in its default configuration. When you tried to install Bundler, RubyGems attempted to fetch the gem spec from the defunct GitHub source, which now returns a 403 Forbidden response because the server either blocks access or has been completely taken offline.
Permanent Solutions
Let's walk through steps to fix this once and for all:
Clean up your gem sources
First, remove the outdated GitHub source (you already did this temporarily, but let's make sure it's gone for good):gem sources --remove "http://gems.github.com"Then, ensure you only have the official, active RubyGems source added:
gem sources --add "https://rubygems.org/"Verify your sources list to confirm no old entries remain:
gem sources -lYou should only see
https://rubygems.org/listed.Install a Bundler version compatible with Ruby 2.5.1
Ruby 2.5.1 doesn't support the latest Bundler versions (like 3.x). To avoid compatibility issues, install a version that works with your Ruby release:# Install a compatible 1.x Bundler version gem install bundler -v '~> 1.17' # Or, if you prefer 2.x, use a compatible release gem install bundler -v '2.0.2'Both these versions are tested to work smoothly with Ruby 2.5.x.
Lock your source configuration permanently
To prevent this issue from recurring, edit your global gem configuration file (~/.gemrc) to enforce the official source. Add or update the file to contain:--- sources: - https://rubygems.org/This ensures every gem operation uses the correct, active registry by default.
Optional: Use a reliable mirror if you face network issues
If you're in a region with slow access to the official RubyGems server, you can use a trusted mirror. Just replace the official source with the mirror URL:gem sources --remove "https://rubygems.org/" gem sources --add "https://gems.ruby-china.com/"Make sure to only use mirrors from reputable organizations.
内容的提问来源于stack exchange,提问作者Wellington1993

