Ubuntu: could not install gem from remote

When install gem from remote, it wait for a long time and then show error, like this:

gem install rails gives me:
ERROR: Could not find a valid gem 'rails' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - timed out (https://api.rubygems.org/specs.4.8.gz)

After trying in debug mode, I get this error:

gem search --remote rails --verbose --debug
NOTE:  Debugging mode prints all exceptions even when rescued

*** REMOTE GEMS ***

Exception `Errno::EEXIST' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/fileutils.rb:250 - File exists @ dir_s_mkdir - /home/dev/.gem/specs/rubygems.org%443
Exception `Net::OpenTimeout' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:960 - execution expired
Exception `Net::OpenTimeout' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:962 - execution expired
Exception `Net::OpenTimeout' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/timeout.rb:116 - execution expired
Exception `Net::OpenTimeout' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/net/http.rb:1025 - execution expired
Exception `Gem::RemoteFetcher::UnknownHostError' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/remote_fetcher.rb:268 - timed out (https://rubygems.org/latest_specs.4.8.gz)
Exception `Gem::RemoteFetcher::UnknownHostError' at /home/dev/.rvm/rubies/ruby-2.7.1/lib/ruby/2.7.0/rubygems/spec_fetcher.rb:256 - timed out (https://rubygems.org/latest_specs.4.8.gz)

I’ve check for certificate but issue still remain.

See: https://bundler.io/v1.16/guides/rubygems_tls_ssl_troubleshooting_guide.html#updating-rubygems

After that, I disable IPv6 and it work.
See: https://help.rubygems.org/discussions/problems/31074-timeout-error

To disable IPv6 for current working session:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

 

Leave a Reply