How can I set a proxy server for gem?

2019-01-08 04:30发布

问题:

I am unable to install SASS through command prompt.

I tried below steps

c:\gem install sass

I am getting below error:

ERROR:  Could not find a valid gem 'sass' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - connect(2) (https://rubygems.org/latest_specs.4.8.gz)

Please help me,

回答1:

For http/https proxy with or without authentication:

Run one of the following commands in cmd.exe

set http_proxy=http://your_proxy:your_port
set http_proxy=http://username:password@your_proxy:your_port
set https_proxy=https://your_proxy:your_port
set https_proxy=https://username:password@your_proxy:your_port


回答2:

You need to write this in the command prompt:

set HTTP_PROXY=http://your_proxy:your_port


回答3:

You need to add http_proxy and https_proxy environment variables as described here.



回答4:

You can try export http_proxy=http://your_proxy:your_port



回答5:

When setting http_proxy and https_proxy, you are also probably going to need no_proxy for URLs on the same side of the proxy. https://msdn.microsoft.com/en-us/library/hh272656(v=vs.120).aspx



回答6:

In Addition to @Yifei answer. If you have special character like @, &, $

You have to go with percent-encode | encode the special characters. E.g. instead of this:

http://foo:B@r@http-gateway.domain.org:80

you write this:

http://foo:B%40r@http-gateway.domain.org:80

So @ gets replaced with %40.



回答7:

None of the answers here actually helped my case (proxy + password), instead I found a solution on a Github issue:

https://github.com/rubygems/rubygems/issues/1068

Basically I had to set three variables:

set http_proxy=proxy_ip:port
set http_proxy_user=user
set http_proxy_pass=password