Ruby-on-rails 如何在代理后面使用捆绑器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3877055/
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
How to use bundler behind a proxy?
提问by bioneuralnet
I get the following output from the sudo bundle installcommand:
我从sudo bundle install命令得到以下输出:
Fetching source index for `http://rubygems.org/`
Could not reach rubygems repository `http://rubygems.org/`
Could not find gem 'rspec-rails (>= 2.0.0.beta.22, runtime)' in any of the gem sources.
I have $http_proxy set correctly and I've added gem: --http-proxy=my proxyto ~/.gemrc. These settings are what allow my gem commands to work, and I was hoping they would translate to bundler, but no such luck.
我正确设置了 $http_proxy 并且已将gem: --http-proxy=my proxy 添加到 ~/.gemrc。这些设置允许我的 gem 命令工作,我希望它们能转换成捆绑器,但没有这样的运气。
Thinking sudo might not inherit my all of my environment, I also added those settings to my root user, but nada.
考虑到 sudo 可能不会继承我的所有环境,我还将这些设置添加到我的 root 用户中,但 nada。
At this point bundler is preventing me from deploying my application, and I can find very few others running into this. If no one has an answer I will be forced to rip bundler out of my Rails app (which I wouldn't mind doing...)
在这一点上,bundler 阻止我部署我的应用程序,我发现很少有其他人遇到这个问题。如果没有人有答案,我将被迫从我的 Rails 应用程序中删除 bundler(我不介意这样做......)
回答by ahmy
OSX & Linux
OSX 和 Linux
export http_proxy=http://user:password@host:port
export HTTP_PROXY=$http_proxy
If it's using HTTPS, set it as well
如果它使用HTTPS,也设置它
export https_proxy=http://user:password@host:port
export HTTPS_PROXY=$https_proxy
If you use sudo, by default sudodoes not preserves http proxy variable. Use -Eflag to preserve it
如果使用sudo,默认情况下sudo不保留 http 代理变量。使用-E标志来保存它
$ sudo -E bundle install
to make sudopreserves environment variables by default:
使sudo默认情况下保留环境变量:
https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/
https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/
Windows
视窗
As pointed by answers below, you can use SETinstead
正如下面的答案所指出的,您可以SET改用
SET HTTP_PROXY=http://user:password@host:port
SET HTTPS_PROXY=%HTTP_PROXY%
回答by Jarl
I figured out that also setting HTTP_PROXY (in addition to http_proxy) made a positive difference, i.e. it worked for me. So assuming that you have set up http_proxyenvironment variable correct, try (if you are using bash)
我发现设置 HTTP_PROXY(除了 http_proxy)也会产生积极的影响,即它对我有用。因此,假设您已http_proxy正确设置环境变量,请尝试(如果您使用的是 bash)
export HTTP_PROXY=$http_proxy
and then also use the -Eoption to sudo (to preserve environment variables), so
然后还使用-Esudo 选项(以保留环境变量),所以
sudo -E bundle install
Jarl
贵族
回答by coorasse
If you don't want to set a global variable in the system you can edit ~/.gemrc and write it like that
如果你不想在系统中设置一个全局变量,你可以编辑 ~/.gemrc 并像这样写
---
:benchmark: false
:verbose: true
:sources:
- http://rubygems.org/
- http://gems.rubyforge.org
:backtrace: false
:bulk_threshold: 1000
:update_sources: true
gem: --http-proxy=http://USERNAME:PASSWORD@ADDRESS:PORT
回答by Jamie.Good
to get bundler behind a proxy on win XP/7 I needed to do the following:
要在 win XP/7 上获得代理后面的 bundler,我需要执行以下操作:
I added http_proxy to the Environment Variables
我在环境变量中添加了 http_proxy
- My Computer
- Advanced system settings
- Advanced Tab Environment
- Variables
- New
- Variable name = http_proxy
- Variable value = MY_PROXY
- Click Ok
- 我的电脑
- 高级系统设置
- 高级选项卡环境
- 变量
- 新的
- 变量名 = http_proxy
- 变量值 = MY_PROXY
- 单击确定
Change MY_PROXY to whatever yours is.
将 MY_PROXY 更改为您的任何内容。
this worked for bundler. The .gemrc proxy setting only worked for gems.
这适用于捆绑器。.gemrc 代理设置仅适用于宝石。
thanks Jamie
谢谢杰米
回答by vladimir
probably more flexible and securable use batch file:
使用批处理文件可能更灵活和安全:
SET /P login="Enter proxy login: "
SET /P password="Enter proxy password: "
SET HTTP_PROXY=http://%login%:%password%@proxy.com:8080
SET HTTPS_PROXY=%HTTP_PROXY%
CLS
bundle install
回答by matttyg
You can download the required gems locally with gem install and then bundle install. Not exactly neat, I know, but it does work.
您可以使用 gem install 在本地下载所需的 gem,然后进行捆绑安装。我知道并不完全整洁,但它确实有效。
回答by Jerry Z.
Windows OS, run following command before execute bundle install
Windows 操作系统,在执行前运行以下命令 bundle install
SET http_proxy=http://user:password@host:port
回答by Pradeep Bihani
$ export http_proxy="http://username:password@host:port"
$ export ftp_proxy="http://username:password@host:port"
$ sudo visudo
Add this line in the file:
在文件中添加这一行:
Defaults env_keep = "http_proxy ftp_proxy"
Above this line:
在这一行之上:
Defaults env_reset
then run your command as sudo it will work.
然后以 sudo 的身份运行您的命令,它将起作用。
ref :https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/
参考:https: //memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/
回答by grayman
I am running Ubuntu. The $http_proxy variable is set, but it doesn't work with a couple items. One of those items being gem.
我正在运行 Ubuntu。$http_proxy 变量已设置,但它不适用于几个项目。其中一项是宝石。
If you put the following in your ~/.gemrc it will work.
如果您将以下内容放入 ~/.gemrc 中,它将起作用。
http_proxy: proxy-url:port
http_proxy:代理网址:端口
Replace the proxy-url:port with your proxy address and port. After I added that, I ran "bundle install" and everything ran as expected.
将 proxy-url:port 替换为您的代理地址和端口。添加后,我运行了“捆绑安装”,一切都按预期运行。
回答by Developer Marius ?il?nas
To have command bundle installwork with proxy on windows do the following:
要bundle install在 Windows 上使用代理执行命令,请执行以下操作:
- Edit file
.gemrc. Open windows command line and type:notepad %userprofile%\.gemrc. - The file .gemrc is open in notepad. Type on a new line
http_proxy: http://username:passwordEncodedWithUrlencode@proxyaddress:proxyport. Password should be encoded with urlencode . - Close the file .gemrc with saving it.
- 编辑文件
.gemrc。打开 windows 命令行并输入:notepad %userprofile%\.gemrc. - 文件 .gemrc 在记事本中打开。键入新行
http_proxy: http://username:passwordEncodedWithUrlencode@proxyaddress:proxyport。密码应使用 urlencode 编码。 - 关闭文件 .gemrc 并保存它。

