原文地址:https://www.zfanw.com/blog/error-while-executing-gem-gem-remote-fetch-error.htmlcss
我對命令行下安裝 gem 包或是 npm 包有很大的心理陰影,由於出現沒法安裝的機率實在太大了 – 每次都要破口大罵 gfw。html
這一回是在更新 gem 時:nginx
gem update --system
返回的錯誤以下:sql
ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)npm
Errno::ETIMEDOUT: Operation timed out – connect(2) for 「s3.amazonaws.com」 port 443 (https://api.rubygems.org/specs.4.8.gz)api
出現 s3 的地址是由於此前 https://rubygems.org 源地址不行,因此執行了 gem source
添加源庫:ruby
gem source --add https://s3.amazonaws.com/production.s3.rubygems.org/
如你所見,仍是報錯。fetch
查了資料,不巧 StackOverflow 上這個問題提到了 Proxy,我國的國情,不掛代理簡直混不下去 IT 業,因此個人 Mac OSX 的代理環境是這樣的:url
privoxy(http://localhost:8118) -> sslEdge(http://localhost:100010)全局
Privoxy 我是用來去除一些廣告。且把死馬當活馬醫吧:spa
export http_proxy=http://localhost:8118 export https_proxy=http://localhost:8118 gem update --system
而後目瞪口呆:
Updating rubygems-update Fetching: rubygems-update-2.4.7.gem (100%) Successfully installed rubygems-update-2.4.7 Parsing documentation for rubygems-update-2.4.7 Installing ri documentation for rubygems-update-2.4.7 Installing darkfish documentation for rubygems-update-2.4.7 Done installing documentation for rubygems-update after 2 seconds Installing RubyGems 2.4.7 RubyGems 2.4.7 installed Parsing documentation for rubygems-2.4.7 Installing ri documentation for rubygems-2.4.7
居然真是代理的問題。因此我猜測是 iterm2 不支持 socks 代理,所以全局並未生效。而經過 Privoxy 的 HTTP 代理作一次轉發,就正常了 – 因此,仍是 gfw 的問題。