Gem RemoteFetcher Fetch Error ECONNREFUSED Solution

Well, you could be here because you tried installing a gem, when you are behind a proxy, either at home or at office and you got a nice error when trying to install as shown below; (I got this while installing Rails for JRuby, but you can get this error for any other gem)
C:\jruby-1.6.2\samples>jruby -S gem install -y rails
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
ERROR:  Could not find a valid gem 'rails' (>= 0) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNREFUSED: Connection refused - Connection refused (http://rubygem
Now, you know the error is because,while installing the gem, the application is not able to get to the network as it does not know how to route itself, when you are behind a proxy. Follow the instructions as shown below, to fix this problem and get going with your installation

In Windows, you have to use the set command to set the value of "http_proxy" variable. If your proxy does not require an authentication, you can set the value by following a sample below;
set http_proxy=http://{hostname}:{portnumber}/
If your proxy require an authentication, then you can specify the user name and password in the same command as shown below;
set http_proxy=http://{username}:{password}@{hostname}:{portnumber}/
set http_proxy=http://username:password@hostname:portnumber/

For other environments, you would want to use "export" instead of "set". Once you do this, you can try installing gems and it should work. (I got it working). Still having an issue? Post it and we will have a look.

1 comment:

  1. dude the solution works very well for me. Thanks a lot for the suggestion.