离线安装 ruby​​ gems/代理配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16959060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:07:36  来源:igfitidea点击:

Install ruby gems offline / proxy configuration

ruby-on-railsrubyproxygem

提问by Vsevolod Semouchin

I need to install ruby on rails + Nokogiri, httparty, json [and some less significant gems] on server which does not have connection to internet. How it could be done?

我需要在没有连接到互联网的服务器上安装 ruby​​ on rails + Nokogiri、httparty、json [和一些不太重要的 gems]。怎么做?

host operating system is windows

主机操作系统是windows

Additional question, well, it is not very good for me, since it can takes some days, but I can as customer to give this server access to the http proxy. However I must confess, that I already tried to use somethin like that

附加问题,嗯,这对我来说不是很好,因为它可能需要几天时间,但我可以作为客户让该服务器访问 http 代理。但是我必须承认,我已经尝试过使用类似的东西

set http_proxy="http://username:password@host:port"

or

或者

gem --http_proxy "http://username:password@host:port"

but in both cases was not able to access the gem store :(

但在这两种情况下都无法访问 gem 商店:(

回答by timhecker

I solved it this way:

我是这样解决的:

set http_proxy=host:port

without any quotes, http:// protocol and username:password. Cheers

没有任何引号,http:// 协议和用户名:密码。干杯

回答by madlymad

Fast solution:

快速解决方案:

gem install -p http://proxy_ip:proxy_port rails

is a fast and working way but I needed something permanent for every installation.

是一种快速且有效的方式,但每次安装我都需要一些永久性的东西。

Permanent solution:

永久解决方案:

  1. Create a file:

    vi ~/.gemrc
    
  2. Add contents

    # HTTP Proxy options
    http_proxy: http://proxy_ip:proxy_port
    https_proxy: http://proxy_ip:proxy_port
    # For authentication (although not tested)
    http_proxy_user: username
    http_proxy_pass: password
    https_proxy_user: username 
    https_proxy_pass: password 
    
  3. Verify proxies appear in gem environment variables

    gem env
    
  1. 创建一个文件:

    vi ~/.gemrc
    
  2. 添加内容

    # HTTP Proxy options
    http_proxy: http://proxy_ip:proxy_port
    https_proxy: http://proxy_ip:proxy_port
    # For authentication (although not tested)
    http_proxy_user: username
    http_proxy_pass: password
    https_proxy_user: username 
    https_proxy_pass: password 
    
  3. 验证代理出现在 gem 环境变量中

    gem env
    


RubyGems Environment: - RUBYGEMS VERSION: 2.5.2 - RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [universal.x86_64-darwin17]

RubyGems 环境: - RUBYGEMS 版本:2.5.2 - RUBY 版本:2.3.3 (2016-11-21 patchlevel 222) [universal.x86_64-darwin17]

回答by Vik

This did the trick for me.

这对我有用。

gem install -p http://proxy_ip:proxy_port rails

gem install -p http://proxy_ip:proxy_port rails

回答by ArNumb

Navigate to the desired gem download page to be installed. For example, I was trying to install Sass, so I googled and reached sass 3.3.14. As I was behind my office proxy, I clicked Downloadlink and downloaded the gem to a directory.

导航到要安装的所需 gem 下载页面。例如,我试图安装 Sass,所以我用谷歌搜索并到达sass 3.3.14。当我在办公室代理后面时,我单击了下载链接并将 gem 下载到一个目录中。

Next, via Ruby command line , navigated to the installed directory using pushd D:\Setupsand used this :

接下来,通过 Ruby 命令行,pushd D:\Setups使用以下命令导航到安装目录:

D:\Setups> gem install sass --local

The desired gem should be installed.

应该安装所需的 gem。

回答by leonhart

You can download all the gems you needed(also there dependencies) from rubygemsto your server,
then run gem install gem_name --localto install them.

您可以从rubygems将所有您需要的 gems(还有依赖项)下载到您的服务器,
然后运行gem install gem_name --local以安装它们。

回答by Colin

For Proxy usage, Wolfbyte's answer worked for me. I'm running on Debian 7 (Wheezy).

对于代理使用,Wolfbyte 的回答对我有用。我在 Debian 7 (Wheezy) 上运行。

How do I update Ruby Gems from behind a Proxy (ISA-NTLM)

如何从代理后面更新 Ruby Gems (ISA-NTLM)

I'll paste his answer below as well:

我也会把他的回答贴在下面:

I wasn't able to get mine working from the command line switch but I have been able to do it just by setting my HTTP_PROXY environment variable (note that case seems to be important). I have a batch file that has a line like this in it:

我无法从命令行开关让我的工作,但我已经能够通过设置我的 HTTP_PROXY 环境变量来做到这一点(请注意,这种情况似乎很重要)。我有一个批处理文件,里面有这样一行:

SET HTTP_PROXY=http://%USER%:%PASSWORD%@%SERVER%:%PORT%

I set the four referenced variables before I get to this line obviously. As an example if my username is wolfbyte, my password is secret and my proxy is called pigsy and operates on port 8080:

我显然在到达这一行之前设置了四个引用变量。举个例子,如果我的用户名是 wolfbyte,我的密码是 secret,我的代理叫 pigsy 并在端口 8080 上运行:

SET HTTP_PROXY=http://wolfbyte:secret@pigsy:8080

You might want to be careful how you manage that because it stores your password in plain text in the machine's session but I don't think it should be too much of an issue.

您可能要小心如何管理它,因为它在机器的会话中以纯文本形式存储您的密码,但我认为这不是一个太大的问题。



In addition, my password had funny characters in it - those you have to URLEncode as per: http://www.cyberciti.biz/faq/unix-linux-export-variable-http_proxy-with-special-characters/

此外,我的密码中有一些有趣的字符 - 您必须按照以下方式进行 URLEncode:http://www.cyberciti.biz/faq/unix-linux-export-variable-http_proxy-with-special-characters/

Hope this helps!

希望这可以帮助!

Colin

科林