やったこと
Rails5 で sidekiq をインストールしようとしたところ、bundle install が失敗してしまいました。
今回、そのエラーを解消したいと思います。
確認環境
$ ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin17]
$ rails --version
Rails 5.2.3
調査
問題の再現
Gemfile
gem 'sidekiq', '~> 5.2', '>= 5.2.7'
bundle install で失敗します
$ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching source index from https://rubygems.org/
Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/
Could not fetch specs from https://rubygems.org/
解決までの過程
bundle update してみます
$ gem update --system
ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
timed out (https://rubygems.org/specs.4.8.gz)
失敗したので、次は、wget できるかやってみます
$ wget https://api.rubygems.org/specs.4.8.gz
--2019-06-15 11:30:11-- https://api.rubygems.org/specs.4.8.gz
Resolving api.rubygems.org... 2a04:4e42::70, 151.101.0.70, 151.101.192.70, ...
Connecting to api.rubygems.org|2a04:4e42::70|:443... failed: Operation timed out.
Connecting to api.rubygems.org|151.101.0.70|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3886510 (3.7M) [application/octet-stream]
Saving to: 'specs.4.8.gz'
specs.4.8.gz 100%[=====================================================================>] 3.71M 1.91MB/s in 1.9s
2019-06-15 11:31:29 (1.91 MB/s) - 'specs.4.8.gz' saved [3886510/3886510]
wget は出来ました。IPv6 での通信に失敗しているようです。
IPv4 を使うようにします。
該当ドメインの IP アドレスを調べます。
$ host api.rubygems.org
api.rubygems.org is an alias for rubygems.org.
rubygems.org has address 151.101.128.70
rubygems.org has address 151.101.0.70
rubygems.org has address 151.101.64.70
rubygems.org has address 151.101.192.70
rubygems.org has IPv6 address 2a04:4e42::70
rubygems.org mail is handled by 10 mxa.mailgun.org.
rubygems.org mail is handled by 10 mxb.mailgun.org.
hosts を書き換えてみます。
$ sudo vim /etc/hosts
151.101.128.70 api.rubygems.org
151.101.0.70 api.rubygems.org
151.101.64.70 api.rubygems.org
151.101.192.70 api.rubygems.org
$ bundle install
sidekiq がインストールできました。