1. 程式人生 > >Ruby中 gem proxy代理設定方法

Ruby中 gem proxy代理設定方法

今天想下載bundler提示:

C:\**********dev>gem install bundler
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/specs.4.8.gz)

windows可以設定代理軟體,或者是使用http_proxy:在命令列輸入:set http_proxy=url,後面的url是你的代理地址,如:http://192.168.0.1:8081,這樣做的結果就是讓自己的命令列會自動使用代理進行網路的轉發,下次重新開啟命令列會自動失效,而不是單純的使用gem的代理,所以可能不是最切實的實現方式,不過這樣一般都能達到目的。

取消代理:
set http_proxy=
然後回車,即等號後面什麼都不寫

檢視代理:
set http_proxy

 

如果相對gem進行單獨的proxy代理的話可以使用:

gem list -p http://proxy:8080

完成之後gem就會從你設定的代理中進行資料的訪問和傳輸了。

gem help 
gem help commands 
gem sources -h 
gem sources -l 
gem sources -r https://rubygem.org/ 
gem sources -a http://ruby.taobao.org
 

when you are behind a proxy.

Set the HTTP_PROXY environment variable.

Note this is fully qualified, as such:
http_proxy=http://URL:PORT

http_proxy=http://127.0.0.1:5865
in this example, the proxy is running on the localhost. With NTLM authorization to get through a corporate firewall.

NB: This may not work if you are behind a Microsoft ISA Proxy server with only NTLM (MS ISA Server proprietary) authentication available. If this is the case, you can try the Microsoft Firewall Client or the Python NTLM Authorization Proxy Server.

JB: A gem is available which gives ruby the ability to authenticate with ISA natively. To use it with gems follow these steps:

  1. Download rubysspi from the Ruby Win32 SSPI project page(also available as gem install rubysspi but that doesn’t help much, does it?)
  2. Install the gem locally
  3. Copy spa.rb from the gem install to your site-ruby directory
  4. Find gem.cmd in your ruby bin directory and add ”-rspa” to the command line.
  5. Set http_proxy environment variable as above
  6. gem list rails