繁体   English   中英

无法在代理后面安装ruby gem

[英]Cannot install ruby gem behind proxy

我已经配置了http_proxy变量,并且能够使用curl和apt-get等。但是,当尝试运行“ gem install bundler”之类的命令时,出现代理错误。 为了让Ruby像其他工具一样尊重代理,我需要做些其他事情吗?

vagrant@mediawiki-vagrant:~$ gem install --debug -V bundler
Exception `NameError' at /usr/lib/ruby/1.9.1/rubygems/command_manager.rb:177 - u
ninitialized constant Gem::Commands::InstallCommand
GET http://rubygems.org/latest_specs.4.8.gz
Exception `Errno::EAGAIN' at /usr/lib/ruby/1.9.1/net/protocol.rb:141 - Resource
temporarily unavailable - read would block
407 Proxy Authentication Required
Exception `Gem::RemoteFetcher::FetchError' at /usr/lib/ruby/1.9.1/rubygems/remot
e_fetcher.rb:222 - bad response Proxy Authentication Required 407 (http://rubyge
ms.org/latest_specs.4.8.gz)
Exception `Gem::RemoteFetcher::FetchError' at /usr/lib/ruby/1.9.1/rubygems/remot
e_fetcher.rb:242 - bad response Proxy Authentication Required 407 (http://rubyge
ms.org/latest_specs.4.8.gz)
Error fetching remote data:             bad response Proxy Authentication Requir
ed 407 (http://rubygems.org/latest_specs.4.8.gz)
Falling back to local-only install
Exception `Gem::GemNotFoundException' at /usr/lib/ruby/1.9.1/rubygems/dependency
_installer.rb:237 - Could not find a valid gem 'bundler' (>= 0) locally or in a
repository
ERROR:  Could not find a valid gem 'bundler' (>= 0) in any repository
GET http://rubygems.org/latest_specs.4.8.gz
Exception `Errno::EAGAIN' at /usr/lib/ruby/1.9.1/net/protocol.rb:141 - Resource
temporarily unavailable - read would block
407 Proxy Authentication Required
Exception `Gem::RemoteFetcher::FetchError' at /usr/lib/ruby/1.9.1/rubygems/remot
e_fetcher.rb:222 - bad response Proxy Authentication Required 407 (http://rubyge
ms.org/latest_specs.4.8.gz)
Exception `Gem::RemoteFetcher::FetchError' at /usr/lib/ruby/1.9.1/rubygems/remot
e_fetcher.rb:242 - bad response Proxy Authentication Required 407 (http://rubyge
ms.org/latest_specs.4.8.gz)
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    bad response Proxy Authentication Required 407 (http://rubygems.org/latest_s
pecs.4.8.gz)
        /usr/lib/ruby/1.9.1/rubygems/remote_fetcher.rb:222:in `fetch_http'
        /usr/lib/ruby/1.9.1/rubygems/remote_fetcher.rb:238:in `fetch_path'
        /usr/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:269:in `load_specs'
        /usr/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:231:in `block in list'
        /usr/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:227:in `each'
        /usr/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:227:in `list'
        /usr/lib/ruby/1.9.1/rubygems/spec_fetcher.rb:189:in `suggest_gems_from_n
ame'
        /usr/lib/ruby/1.9.1/rubygems/command.rb:160:in `show_lookup_failure'
        /usr/lib/ruby/1.9.1/rubygems/commands/install_command.rb:132:in `rescue
in block in execute'
        /usr/lib/ruby/1.9.1/rubygems/commands/install_command.rb:116:in `block i
n execute'
        /usr/lib/ruby/1.9.1/rubygems/commands/install_command.rb:115:in `each'
        /usr/lib/ruby/1.9.1/rubygems/commands/install_command.rb:115:in `execute
'
        /usr/lib/ruby/1.9.1/rubygems/command.rb:278:in `invoke'
        /usr/lib/ruby/1.9.1/rubygems/command_manager.rb:147:in `process_args'
        /usr/lib/ruby/1.9.1/rubygems/command_manager.rb:117:in `run'
        /usr/lib/ruby/1.9.1/rubygems/gem_runner.rb:65:in `run'
        /usr/bin/gem:21:in `<main>'

只是更精确一些。
407 Proxy Authentication Required错误意味着您必须为代理使用登录名和密码

您可以使用--http-proxy选项将其添加,格式如下:

gem install --http-proxy http://login:password@proxyServer:proxyPort yourGem

但是, 如果您的密码包含某些特殊字符 ,则此方法将无效
实际上,由于选项值必须与URL匹配 ,因此禁止使用某些字符。

如果不确定,可以在执行命令之前在shell中执行以下操作,而不用在gem install命令中指定代理:

set HTTP_PROXY=http://proxyServer:proxyPort
set HTTP_PROXY_USER=login
set HTTP_PROXY_PASS=password
set HTTPS_PROXY=http://proxyServer:proxyPort
set HTTPS_PROXY_USER=login
set HTTPS_PROXY_PASS=password

尝试这个:

sudo HTTP_PROXY =“ http://10.3.100.207:8080” gem install bundler

将“ 10.3.100.207”替换为代理,将“ 8080”替换为端口值”

它为我工作。

尝试将http-proxy设置添加到您的〜/ .gemrc文件中。

示例gemrc

--- 
gem: --no-ri --no-rdoc
http-proxy: http://example.com:80

我可以通过下载和配置ntlmaps来解决此问题。 很棒。 由于某种原因,gemrc文件代理没有帮助。

您必须在家庭用户文件夹的.bashrc文件中导出代理环境变量:

将这些行添加到.bashrc的末尾

export http_proxy="http://proxy:80"
export https_proxy="http://proxy:80"

记住要打开一个新的外壳程序窗口,以便外壳程序可以重新加载.bashrc文件。

如果使用sudo,则可以选择以root用户身份使用用户的环境变量,请编辑/etc/sudores文件并添加以下行:

Defaults env_keep += "http_proxy https_proxy"

如果您需要Microsoft代理上的代理身份验证,我建议使用cntlm代理: http ://cntlm.sourceforge.net/

默认情况下,cntlm使用3128端口,因此您必须更改.bashrc的环境变量:

export http_proxy="http://localhost:3128"
export https_proxy="http://localhost:3128"

要配置cntlm,这很容易解释,这里是重要的选项:

#
# Cntlm Authentication Proxy Configuration
#
# NOTE: all values are parsed literally, do NOT escape spaces,
# do not quote. Use 0600 perms if you use plaintext password.
#

Username        testuser
Domain          corp-uk
Password        password
# NOTE: Use plaintext password only at your own risk
# Use hashes instead. You can use a "cntlm -M" and "cntlm -H"
# command sequence to get the right config for your environment.
# See cntlm man page
# Example secure config shown below.
# PassLM          1AD35398BE6565DDB5C4EF70C0593492
# PassNT          77B9081511704EE852F94227CF48A793
### Only for user 'testuser', domain 'corp-uk'
# PassNTLMv2      D5826E9C665C37C80B53397D5C07BBCB

# Specify the netbios hostname cntlm will send to the parent
# proxies. Normally the value is auto-guessed.
#
# Workstation   netbios_hostname

# List of parent proxies to use. More proxies can be defined
# one per line in format <proxy_ip>:<proxy_port>
#
Proxy           10.0.0.41:8080
Proxy           10.0.0.42:8080
[...]

对我来说@thomas提到的是有效的...

set HTTP_PROXY=http://proxyServer:proxyPort
set HTTP_PROXY_USER=login
set HTTP_PROXY_PASS=password
set HTTPS_PROXY=http://proxyServer:proxyPort
set HTTPS_PROXY_USER=login
set HTTPS_PROXY_PASS=password

采用:

gem install --http-proxy http:// proxy-UserPass @ Proxy-Name代理端口 gem-XYZ

您的通行证必须简单,没有特殊字符,否则会返回错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM