简体   繁体   English

无法在代理后面安装ruby gem

[英]Cannot install ruby gem behind proxy

I have configured my http_proxy variable, and am able to use curl, and apt-get, etc. However, when trying to run a command such as "gem install bundler" I get a proxy error. 我已经配置了http_proxy变量,并且能够使用curl和apt-get等。但是,当尝试运行“ gem install bundler”之类的命令时,出现代理错误。 Is there something different I need to do in order to get Ruby to respect the proxy like every other tool is doing? 为了让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>'

Just some more precision. 只是更精确一些。
Your 407 Proxy Authentication Required error means you have to use a login and password for your proxy . 407 Proxy Authentication Required错误意味着您必须为代理使用登录名和密码

You can use the --http-proxy option to add it, with the following pattern: 您可以使用--http-proxy选项将其添加,格式如下:

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

BUT, this will not work if your password contains some special character . 但是, 如果您的密码包含某些特殊字符 ,则此方法将无效
Effectively, as the option value must match an URL , some characters are forbidden. 实际上,由于选项值必须与URL匹配 ,因此禁止使用某些字符。

If you are unsure, instead of specifying the proxy in the gem install command, you can do in the shell, before executing the command, with: 如果不确定,可以在执行命令之前在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

Try this: 尝试这个:

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

Replace "10.3.100.207" with your proxy and "8080" with your port value" 将“ 10.3.100.207”替换为代理,将“ 8080”替换为端口值”

It worked for me. 它为我工作。

Try adding the http-proxy setting to your ~/.gemrc file. 尝试将http-proxy设置添加到您的〜/ .gemrc文件中。

Example gemrc 示例gemrc

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

I was able to solve this by downloading and configuring ntlmaps. 我可以通过下载和配置ntlmaps来解决此问题。 Worked great. 很棒。 For some reason the gemrc file proxy did not help. 由于某种原因,gemrc文件代理没有帮助。

You have to export the proxy environment variables in the .bashrc file of your home user folder: 您必须在家庭用户文件夹的.bashrc文件中导出代理环境变量:

Add these lines at the end of your .bashrc 将这些行添加到.bashrc的末尾

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

Remembert to open a new shell window, so the shell can reload the .bashrc file. 记住要打开一个新的外壳程序窗口,以便外壳程序可以重新加载.bashrc文件。

If you are using sudo there's an option to use the environment vars of the user as root, edit your /etc/sudores file and add this line: 如果使用sudo,则可以选择以root用户身份使用用户的环境变量,请编辑/etc/sudores文件并添加以下行:

Defaults env_keep += "http_proxy https_proxy"

If you need proxy authentication on a microsoft proxy, i recommend the cntlm proxy: http://cntlm.sourceforge.net/ 如果您需要Microsoft代理上的代理身份验证,我建议使用cntlm代理: http ://cntlm.sourceforge.net/

By default cntlm uses the 3128 port, so you have to change the environment variables of .bashrc : 默认情况下,cntlm使用3128端口,因此您必须更改.bashrc的环境变量:

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

To configure cntlm it is pretty self explanatory, here you are the important options: 要配置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
[...]

For me what @thomas mentioned worked ... 对我来说@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

use: 采用:

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

Your pass need be simple, without special characters or will return an error. 您的通行证必须简单,没有特殊字符,否则会返回错误。

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

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