69

I've been trying to install this 'rubygame' gem for some time, but whenever I use the command

gem install rubygame

it will give an error:

ERROR:  Could not find a valid gem 'rubygame' (>= 0) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)

I've also tried other gems but with similar results:

ERROR:  Could not find a valid gem 'rake' (>= 0) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)

I've already made sure I have an internet connection, and have already tried reinstalling both ruby and rubygems (currently using ruby 1.8, rubygems 1.7.2). Googling didn't help me at all. I would be very grateful if anyone can solve my problem. My sources list only shows http://rubygems.org

Reiswindy
  • 789
  • 1
  • 6
  • 7
  • For some reason it started working fine today. I don't know how it got solved. Thanks for the help anyway. – Reiswindy Apr 04 '12 at 15:32
  • 2
    The problem is due to the proxy server which can be solved by using the command : gem install package --http-proxy=http://user:pass@proxy:port_no Here if you do not have a username or password ignore them and just mention your proxy address and port number after the "@" https://forums.openshift.com/gem-install-rhc-error – Jeyan Nov 11 '14 at 10:24

17 Answers17

92

Check if you have "https://rubygems.org/" as a source to find gems at:

$ gem sources
*** CURRENT SOURCES ***

https://rubygems.org/

If not, you should be able to add it with

$ gem sources --add https://rubygems.org/
https://rubygems.org/ added to sources

Here are docs for the gem source command.

KrauseFx
  • 11,551
  • 7
  • 46
  • 53
Joshua Cheek
  • 30,436
  • 16
  • 74
  • 83
  • 8
    Thankkyou so much for the soution, omg Ruby adds by default a secure HTTPS connection as source... I added manually the same source using http: and it worked fine – ElektroStudios Dec 26 '14 at 19:05
  • 1
    did not work !!! SSL problem. @Apprentice solution is nice. http://stackoverflow.com/a/18063512/2369867 – mythicalcoder Feb 15 '17 at 20:17
53

You can also add the source you want on the command whenever you have troubles using https, like this:

gem install GEMNAME --source http://rubygems.org

It's better to fix the SSL problem though.

Apprentice
  • 681
  • 6
  • 9
  • 2
    I was just scrolling to try each answer here and you made it :D thank you a lot. No proxy or sth needed. – Eray Tuncer Dec 28 '14 at 00:44
  • 1
    Weird, this is the only solution that worked for me. – Lenar Hoyt Jun 18 '16 at 16:55
  • I eventually fixed installing ruby 2.4.2 on osx by running `brew unlink pkg-config` recompiling and installing ruby, then `brew link pkg-config` and installing the bundler gem `gem install bundler`. This was fixed in ruby 2.5.0. I was also using chruby+ruby_install. Also making heavy use of `rehash` command to discover new binaries. – Harry Moreno Feb 19 '18 at 21:40
  • mate after hours of searching for ssl errors this worked – gaut Oct 10 '19 at 10:48
26

are you behind any proxy?

check your browser for proxy that you might use:

execute the command: gem install xxx --http-proxy=http://user:password@server and you should be good to go.

aakash
  • 751
  • 5
  • 18
24

You don't have an Internet connection to rubygems.org.

This happens sometimes if the site is down or blocked.

This command can show you if your connection has a way to reach rubygems.org:

traceroute rubygems.org
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • According to ping, "0% packet lost". I don't understand much about traceroute and tracepath but it seems I got a response from the server in traceroute and "no reply" from tracepath. – Reiswindy Apr 01 '12 at 05:26
  • That's good news. The traceroute and tracepath should show you the step-by-step connection to the rubygems server. The next step is to ask if there's any chance you're behind some kind of firewall that may be blocking your downloads? Also, try the code in my next answer. – joelparkerhenderson Apr 01 '12 at 05:42
  • 2
    [this person](http://stackoverflow.com/a/15464012/2668831) says rubygems.org doesn't respond to ping requests. I'm seeing 100% packets lost, but gem search is working... – Louis Maddox Nov 30 '13 at 20:30
14

Maybe you should try

gem list -r

then

gem install -r rubygame

Also note that with rvmon MacosX (Lion in my case) you should install ruby-1.9.3-p194 (for Xcode 4.x compiler considerations) then

rvm rubygems current

and in my case I had to use

rvm use ruby-1.9.3-p194@global

(which contains bundler, rake, rubygems-bundlerand rvm)

and not

rvm use ruby-1.9.3-p194

(which is empty)

Peter Host
  • 1,346
  • 11
  • 10
10

Can you post your versions?

ruby -v
#=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

gem -v
#=> 1.8.19

If your gem command is not current, you can update it like this:

gem update --system

To see if you can connect to rubygems.org using Ruby:

require 'net/http'
require 'uri'
puts Net::HTTP.get URI.parse('https://rubygems.org')

If yes, that's good.

If no, then somehow Ruby is blocked from opening a net connection. Try these and see if any of them work:

curl https://rubygems.org

curl https://rubygems.org --local-port 1080

curl https://rubygems.org --local-port 8080

env | grep -i proxy

If you're using a company machine, or within a company firewall, or running your own firewall, you may need to use a proxy.

For info on Ruby and proxies see http://www.linux-support.com/cms/http-proxies-and-ruby/


Andrew White
  • 600
  • 1
  • 9
  • 29
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • Ruby version is: ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux] Gem version is: 1.7.2 EDIT: The code showed this... /usr/lib/ruby/1.8/net/http.rb:560:in `initialize': Connection timed out - connect(2) (Errno::ETIMEDOUT) – Reiswindy Apr 01 '12 at 05:59
  • Your code result shows that Ruby is unable to open a connection. This narrows it down. What kind of system are you using (for example a your own laptop?), what operating system (for example, Mac OSX), and what kind of firewall software are you using – joelparkerhenderson Apr 01 '12 at 07:50
  • I'm using my own laptop with Ubuntu 11.10. I'm not sure about a firewall. (ufw disabled apparently). curl either returned 'couldn't connect to host' or nothing at all. env command returned returned UBUNTU_MENUPROXY=libappmenu.so – Reiswindy Apr 01 '12 at 16:37
  • Good, if this one "curl http://rubygems.org" returned "couldn't connect to host" then you've proven the problem isn't your Ruby setup. Do you connect to something like a company network or school network? Also try turning off your firewall like the notes here: https://help.ubuntu.com/11.10/ubuntu-help/net-firewall-on-off.html – joelparkerhenderson Apr 01 '12 at 23:59
  • I'm only connecting through my home network (a wireless router) so I'm almost certain on not using a proxy. Also my firewall is disabled. – Reiswindy Apr 02 '12 at 00:16
8

I have fixed this issue using the proxy command option of gem install. It has the following format:

$ gem install --http-proxy http://201.187.107.19:8080 rubygame

Note, the IP address and the port number refers to a proxy. You should search for a proxy list and use one of the proxies there.

This is site with proxies: http://www.cybersyndrome.net/pla5.html

Also, I have to try 7 or 8 different proxies in order to succeed. Do not give up.

gotqn
  • 42,737
  • 46
  • 157
  • 243
5

Use :

gem sources --add http://rubygems.org/

Do you want to add this insecure source? [yn] [YES]

then use

gem install sass

and done

Wasim Khan
  • 1,177
  • 12
  • 13
3

I know this is a little late, but I was also having this issue a while ago. This is what worked for me:

REALLY_GEM_UPDATE_SYSTEM=1 
sudo gem update --system
sudo gem install rails

Hope this helps anyone else having this issue :)

Farhan Ahmad
  • 5,148
  • 6
  • 40
  • 69
3

I have tried most of the solutions suggested here but I had no luck. I found a solution that worked for me, which was manually updating the gemfile to 2.6.7. The guide on how to do is in guides.rubygems.org: installing-using-update-packages

Download rubygems-update-2.6.7.gem to your C:\

Now, using your Command Prompt:

C:\>gem install --local C:\rubygems-update-2.6.7.gem
C:\>update_rubygems --no-ri --no-rdoc 

After this, gem --version should report the new update version (2.6.7).

You can now safely uninstall rubygems-update gem:

C:\>gem uninstall rubygems-update -x
Removing update_rubygems
Successfully uninstalled rubygems-update-2.6.7

The reason why this did not work before was because server used certificates SHA-1, now this was updated to SHA-2.

Snake Sanders
  • 2,641
  • 2
  • 31
  • 42
1

For what it is worth I came to this page because I had the same problem. I never got anywhere except some IMAP stuff that I don't understand. Then I remembered I had uninstalled privoxy on my ubuntu (because of some weird runtime error that mentioned 127.0.0.1:8118 when I used Daniel Kehoe's Rails template, https://github.com/RailsApps/rails3-application-templates [never discovered what it was]) and I hadn't changed my terminal to the state of no system wide proxy, under network proxy.

I know this may not be on-point but if I wound up here maybe other privoxy users can benefit too.

nate
  • 269
  • 2
  • 11
1

check your DNS settings ...I was facing similar problem ... when I checked my /etc/resolve.config file ,the name server was missing ... after adding it the problem gets resolved

0

This worked for me to bypass the proxy definitions:

1) become root

2) gem install -u gem_name gem_name

Hope you can work it out

Tiago Duarte
  • 145
  • 1
  • 1
  • 6
0

I tried to install a gem which is for JRuby only, running into the same error. Using jruby's command worked then:

jruby -S gem install some_jruby_gem
SimonH
  • 1,385
  • 15
  • 35
0

If you are running behind the any firewall(if firewall blocking gem installation). just try following command it works.

 gem install --http-proxy http://username:pwd@server:port gem
Siddu hadapad
  • 3,023
  • 5
  • 15
  • 26
-1

Make sure you type the command from the "App" Directory

Darix
  • 1
  • 1
-6

It is a permission issue.

try with sudo

acmoune
  • 2,981
  • 3
  • 24
  • 41