前提・実現したいこと
bundle installしたい。
発生している問題・エラーメッセージ
$ bundle install Your Gemfile lists the gem pg (= 1.1.4) more than once. You should probably keep only one of them. Remove any duplicate entries and specify the gem only once. While it's not a problem now, it could cause errors if you change the version of one of them later. Fetching source index from https://rubygems.org/ Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ due to underlying error <Net::OpenTimeout: execution expired (https://rubygems.org/specs.4.8.gz)> Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ due to underlying error <Net::OpenTimeout: execution expired (https://rubygems.org/specs.4.8.gz)> Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/ due to underlying error <Net::OpenTimeout: execution expired (https://rubygems.org/specs.4.8.gz)> Could not fetch specs from https://rubygems.org/ due to underlying error <Net::OpenTimeout: execution expired (https://rubygems.org/specs.4.8.gz)>
該当のソースコード
ruby
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.7.1' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' 7gem 'rails', '~> 6.1.4', '>= 6.1.4.1' 8# Use Puma as the app server 9gem 'puma', '~> 5.0' 10# Use SCSS for stylesheets 11gem 'sass-rails', '>= 6' 12# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 13gem 'webpacker', '~> 5.0' 14# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 15gem 'turbolinks', '~> 5' 16# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 17gem 'jbuilder', '~> 2.7' 18# Use Redis adapter to run Action Cable in production 19# gem 'redis', '~> 4.0' 20# Use Active Model has_secure_password 21# gem 'bcrypt', '~> 3.1.7' 22 23# Use Active Storage variant 24# gem 'image_processing', '~> 1.2' 25 26# Reduces boot times through caching; required in config/boot.rb 27gem 'bootsnap', '>= 1.4.4', require: false 28 29group :development, :test do 30 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 31 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 32 gem 'pg', '1.1.4' 33end 34 35group :development do 36 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 37 gem 'web-console', '>= 4.1.0' 38 # Display performance information such as SQL time and flame graphs for each request in your browser. 39 # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md 40 gem 'rack-mini-profiler', '~> 2.0' 41 gem 'listen', '~> 3.3' 42 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 43 gem 'spring' 44end 45 46group :test do 47 # Adds support for Capybara system testing and selenium driver 48 gem 'capybara', '>= 3.26' 49 gem 'selenium-webdriver' 50 # Easy installation and use of web drivers to run system tests with browsers 51 gem 'webdrivers' 52end 53 54group :production do 55 gem 'pg', '1.1.4' 56end 57# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 58gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 59 60gem 'bootstrap' 61gem 'dotenv-rails'
試したこと
- wgetでリクエストを投げて確認してみるとIPv6の場合だけ接続に失敗することを確認した。
text
1$ wget https://rubygems.org/specs.4.8.gz 2--2021-09-30 04:59:18-- https://rubygems.org/specs.4.8.gz 3Resolving rubygems.org (rubygems.org)... 2a04:4e42:200::483, 2a04:4e42::483, 2a04:4e42:400::483, ... 4Connecting to rubygems.org (rubygems.org)|2a04:4e42:200::483|:443... failed: Operation timed out. 5Connecting to rubygems.org (rubygems.org)|2a04:4e42::483|:443... failed: Operation timed out. 6Connecting to rubygems.org (rubygems.org)|2a04:4e42:400::483|:443... failed: Operation timed out. 7Connecting to rubygems.org (rubygems.org)|2a04:4e42:600::483|:443... failed: Operation timed out. 8Connecting to rubygems.org (rubygems.org)|151.101.193.227|:443... connected. 9HTTP request sent, awaiting response... 200 OK 10Length: 4485268 (4.3M) [application/octet-stream] 11Saving to: ‘specs.4.8.gz.1’
- gem cannot access rubygems.orgには以下のことが書いてありました。
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
, yourgem
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 thatgem
will try IPv4 addresses first. In order to do it, put these lines into/etc/gai.conf
:
- 以上のことから、
sudo vi /etc/gai.conf
で、以下を記述しましたが変わりがなかったです。
text
1# Debian defaults. 2precedence ::1/128 50 3precedence ::/0 40 4precedence 2002::/16 30 5precedence ::/96 20 6precedence ::ffff:0:0/96 10 7 8# Low precedence for api.rubygems.org IPv6 addresses. 9precedence 2a04:4e42::0/32 5
- rubygems.orgのIPv4アドレスを調べてhostsに記載もしてみましたが変わらなかったです。
text
1$ host rubygems.org 2rubygems.org has address 151.101.193.227 3rubygems.org has address 151.101.129.227 4rubygems.org has address 151.101.65.227 5rubygems.org has address 151.101.1.227 6rubygems.org has IPv6 address 2a04:4e42:600::483 7rubygems.org has IPv6 address 2a04:4e42::483 8rubygems.org has IPv6 address 2a04:4e42:200::483 9rubygems.org has IPv6 address 2a04:4e42:400::483 10rubygems.org mail is handled by 10 mxb.mailgun.org. 11rubygems.org mail is handled by 10 mxa.mailgun.org.
text
1$ sudo vi /etc/hosts 2## 3# Host Database 4# 5# localhost is used to configure the loopback interface 6# when the system is booting. Do not change this entry. 7## 127.0.0.1 localhost 8255.255.255.255 broadcasthost ::1 localhost 9 10/* 記述*/ 11151.101.129.227 rubygems.org 12151.101.65.227 rubygems.org 13151.101.1.227 rubygems.org 14151.101.193.227 rubygems.org 15
- 以上のことをしても、変わりはなかったので、
gem update --system
してみたところ、以下のようなエラーが出ました。
text
1$ gem update --system 2ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) 3 Net::OpenTimeout: execution expired (https://rubygems.org/specs.4.8.gz)
参考
- rails5.2 bundle installがこけるので原因を調査してみた - Qiita
- gem cannot access rubygems.org
- rubygems.orgにアクセスできなくなった場合の解決法
手詰まりになってわからなくなってしまいました。
よろしくお願いします。
補足情報(FW/ツールのバージョンなど)
- ruby 2.7.1
- Rails 6.1.4.1
- Bundler v2.2.24
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。