12

I'm trying to install the bundler gem using $ gem install bundler. When I execute the command, I receive the following response:

ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
    Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation   timed out - connect(2) (https://api.rubygems.org/latest_specs.4.8.gz)
ERROR:  Possible alternatives: bundler

In an effort to make sure I wasn't going crazy, I tried installing nokogiri:

ERROR:  Could not find a valid gem 'nokogiri' (>= 0), here is why:
  Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://api.rubygems.org/latest_specs.4.8.gz)
ERROR:  Possible alternatives: nokogiri

And a2z:

ERROR:  Could not find a valid gem 'a2z' (>= 0), here is why:
  Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://api.rubygems.org/quick/Marshal.4.8/a2z-0.1.3.gemspec.rz)

If anyone has experience this issue before and can help me out it would be greatly appreciated.

If it helps, I'm running MacOS Mavericks and have gem version 2.2.2.

2

13 Answers 13

20

I resolved this issue disabling the IPv6 connections in my system OS.

It forces the OS just use the IPv4 and then it works.

3
  • 1
    Thanks, this worked. And since I had "Off" option missing in my Ethernet settings, I had to use CLI command networksetup -setv6off Ethernet
    – RAM237
    Jan 21, 2020 at 15:12
  • Thanks - had this strange and obscure problem too. Both answer and comment here helped a lot.
    – user37309
    Aug 20, 2020 at 5:49
  • 2
    On Debian: sysctl -w net.ipv6.conf.default.disable_ipv6=1; sysctl -w net.ipv6.conf.all.disable_ipv6=1
    – rodvlopes
    Oct 10, 2020 at 0:38
9

For people using Windows, the following worked for me on Windows 10. See also my reply on the ruby gems issues list.

  1. Go to Control Panel > Network and Internet > Network connections
  2. Select the network connection you're currently using
  3. Right click on it and choose Properties
  4. Remove check mark for Internet Protocol version 6 (TCP/IPv6)
  5. Click OK
  6. Run your gem command again
1
  • Thank you for the comment explaining how to do this on Windows. This fix didn't work for me, as I ended up not having any internet (even though ipv4 was checked by default) so I had to unplug and replug my wifi usb stick and change it back to get internet
    – Justin
    May 28, 2021 at 5:58
6

In your Gemfile set your

source 'http://production.s3.rubygems.org'

This may not be an official answer, but it worked for me after three frustrating days trying to access rubygems.org.

4
  • This seemed to resolve itself after a day or two. I think there may have been a connection issue with their servers.
    – Matt
    Aug 19, 2014 at 19:44
  • actually in my case it had been my fault - DNS pointed to an old address, which I had put in earlier to get around annother DNS problem Aug 20, 2014 at 14:12
  • 2
    Can you give an example of what the full command line would look like? Do you put the source in front of the install command or after? Nov 10, 2016 at 9:05
  • e.g gem sources -a 'http://production.s3.rubygems.org'. But this did not work for me. Oct 1, 2021 at 16:44
5

i had the same issue which i solved by disabling my VPN. try looking at proxies, VPNs, and other networking issues.

0
3

api.rubygems.org is having issues with IPV6 host address. I faced the same issue after I setup the ubuntu server in vbox. We need to configure it to use our host's IPV4 first and then try IPV6.

So we can change the priority by adding this line ti /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

And it worked like a charm!

3
  1. ping rubygems.org and get the IP address.
  2. Edit your /etc/hosts file and add the line: <IPADD> rubygems.org.
  3. gem update --system.
3

For the people using macOS, the following worked me on macOS 12.3.1.

  1. Go to System Preferences > Network
  2. Click on the Advanced... button
  3. Go to TCP/IP tab on the top
  4. Change Configure IPv6 from Automatically to Manually
  5. Click on the OK
  6. Click on the Apply
  7. Re-try installing your gems
  8. Revert the changes back
2

I encountered this just now. I needed to disable IPv6. I had to set mine to link-local only to get it to work. Otherwise, it's the same as @chootti's list:

  1. Go to System Preferences > Network
  2. Click on the Advanced... button
  3. Go to TCP/IP tab on the top
  4. Change Configure IPv6 from Automatically to Link-local only
  5. Click on OK

Then I ran sudo gem update --system to update RubyGems. I still couldn't install gems with IPv6 enabled, so it looks like that needs to be off to install from RubyGems.

Machine this worked on:

OS: MacOS Monterey 12.4

Machine: Apple M1 (2020)

Ruby install manager: ASDF

1

just add --source http://rubygems.org to your installs. The issue most likely is with your internet connection.

1

In my case helped the following:

sudo gem update --system
2
  • 1
    In my case even this is throwing a timeout issue
    – Emjey
    Jun 21, 2018 at 12:09
  • 2
    This is purely a Network and DNS config issue. I ran into the same thing, checked with a network which is not bound to any strict firewalls and auto-configured DNS, this worked. Looks like the source url of repo starts from https and not https, that maybe the cause. Just a guess, not sure. Aug 8, 2018 at 7:04
1
  1. Disable ipv6
  2. sudo gem update --system
  3. gem install bundler
0

I ran into the same issue. Try running:

bundle pristine
0

dig api.rubygems.org +short

Adding below line to /etc/hosts worked for me:

151.101.192.70  rubygems.org

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.