无法在代理后面安装ruby gem

时间:2014-07-16 21:57:28

标签: ruby proxy vagrant

我已经配置了我的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>'

7 个答案:

答案 0 :(得分:8)

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

您可以使用--http-proxy选项添加它,使用以下模式:

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

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

如果您不确定,可以在执行命令之前在shell中执行:{/ p>,而不是在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

答案 1 :(得分:1)

试试这个:

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

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

它对我有用。

答案 2 :(得分:0)

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

示例gemrc

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

答案 3 :(得分:0)

我能够通过下载和配置ntlmaps来解决这个问题。工作得很好。由于某种原因,gemrc文件代理没有帮助。

答案 4 :(得分:0)

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

在.bashrc

的末尾添加这些行
export http_proxy="http://proxy:80"
export https_proxy="http://proxy:80"

Remembert打开一个新的shell窗口,因此shell可以重新加载.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
[...]

答案 5 :(得分:0)

对我来说@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

答案 6 :(得分:0)

使用:

  

gem安装--http-proxy   http:// 代理用户通过 @ 代理名称代理端口   gem-XYZ

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