替换Ruby Gems 默认源

经常因为网络问题,执行 sudo gem update –system 报错

ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNREFUSED: Failed to open TCP connection to rubygems.org:443 (Connection refused - connect(2) for "rubygems.org" port 443) (https://rubygems.org/specs.4.8.gz)

使用 gem sources -l 查看本地默认源

*** CURRENT SOURCES ***

https://rubygems.org/

更换 gem 默认源

# 添加 TUNA 源并移除默认源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
# 列出已有源
gem sources -l
# 应该只有 TUNA 一个