问题
I have a server with Rackspace that I use for a few Ruby sites. When I try bundle install
on a new site I get
Retrying download gem from http://rubygems.org/ due to error (2/4): Gem::RemoteFetcher::UnknownHostError timed out (http://rubygems.org/gems/rake-12.3.1.gem)
Or trying gem update --system
I get
ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
timed out (http://api.rubygems.org/specs.4.8.gz)
What I have tried:
- Using curl to download the gem URL in the first error (successful)
- Change gem source from https://rubygems.org to http://rubygems.org
- Change the name servers on the slice to use Google's
- Downloading and updating
gem
from source (on 2.7.6) - Run
apt-get update
- Adding
AddTrustExternalCARoot-2048.pem
What I haven't tried:
- Animal sacrifice
- Lucky rabbit foot
- Deleting all files and reinstalling the image
I was finally (just before submitting this) able to get bundle install
to work by removing rubygems.org as a source and adding https://gems.ruby-china.org/. Why would gem be unable to access rubygems.org?
回答1:
api.rubygems.org
is currently experiencing issues with IPv6 setup: this hostname has 4 IPv6 addresses, but responds on neither of them. Neither to ping
, nor to TCP connection attempts. When you are running gem
, your gem
tries IPv6 addresses first and times out on them, not having time to even try IPv4 addresses.
The solution is to lower priority of IPv6 addresses for api.rubygems.org
, so that gem
will try IPv4 addresses first. In order to do it, put these lines into /etc/gai.conf
:
# Debian defaults.
precedence ::1/128 50
precedence ::/0 40
precedence 2002::/16 30
precedence ::/96 20
precedence ::ffff:0:0/96 10
# Low precedence for api.rubygems.org IPv6 addresses.
precedence 2a04:4e42::0/32 5
回答2:
I didn't find /etc/gai.conf
on MacOS, so as a workaround I just disabled IPV6 to download the gems. That worked for me.
'System Preferences' -> 'Network' -> Select WiFi -> click 'Advanced' button -> select 'TCP/IP' tab -> set the Configure IPV6 select to 'link-local only'.
回答3:
I added the line below to my /etc/hosts and it works.
151.101.192.70 rubygems.org
回答4:
As of this date, the IPv6 issues with rubygems.org still exist, although it seems not all the time or everywhere. I ran into it with VPSs in one data center, but not those in another. Alexei Khlebnikov's answer above is by far the best and easiest way to work around the problem (at least on Linux). However, make sure to do your own lookup for the api.rubygems.org IPv6 addresses; I found that the specific addresses above are no longer correct.
$ dig AAAA api.rubygems.org +short
rubygems.org.
2a04:4e42::70
2a04:4e42:400::70
2a04:4e42:600::70
2a04:4e42:200::70
回答5:
For Windows users, the problem can be resolved by prioritizing IPv4 addresses over IPv6 (see https://superuser.com/a/436944). Check your prefix policies by using PowerShell as administrator:
netsh interface ipv6 show prefixpolicies
You should see that IPv6 addresses (::/0) have higher precedence over IPv4 (::/96 and ::ffff:0:0/96). To fix this, delete the IPv6 entry and re-add it with a lower precedence, for example:
netsh interface ipv6 del prefixpolicy ::/0
netsh interface ipv6 add prefixpolicy ::/0 3 6
where the precedence 3 on my machine was lower than all others, and the label 6 was unused.
来源:https://stackoverflow.com/questions/49800432/gem-cannot-access-rubygems-org