How to use bundler behind a proxy?
Ruby on-RailsRubyProxyRubygemsBundlerRuby on-Rails Problem Overview
I get the following output from the sudo bundle install command:
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 proxy to ~/.gemrc. These settings are what allow my gem commands to work, and I was hoping they would translate to bundler, but no such luck.
Thinking sudo might not inherit my all of my environment, I also added those settings to my root user, but 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...)
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
OSX & Linux
export http_proxy=http://user:password@host:port
export HTTP_PROXY=$http_proxy
If it's using HTTPS, set it as well
export https_proxy=http://user:password@host:port
export HTTPS_PROXY=$https_proxy
If you use sudo
, by default sudo
does not preserves http proxy variable. Use -E
flag to preserve it
$ sudo -E bundle install
to make sudo
preserves environment variables by default:
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 SET
instead
SET HTTP_PROXY=http://user:password@host:port
SET HTTPS_PROXY=%HTTP_PROXY%
Solution 2 - Ruby on-Rails
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_proxy
environment variable correct, try (if you are using bash)
export HTTP_PROXY=$http_proxy
and then also use the -E
option to sudo (to preserve environment variables), so
sudo -E bundle install
Jarl
Solution 3 - Ruby on-Rails
If you don't want to set a global variable in the system you can edit ~/.gemrc and write it like that
---
: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
Solution 4 - Ruby on-Rails
to get bundler behind a proxy on win XP/7 I needed to do the following:
I added http_proxy to the Environment Variables
- My Computer
- Advanced system settings
- Advanced Tab Environment
- Variables
- New
- Variable name = http_proxy
- Variable value = MY_PROXY
- Click Ok
Change MY_PROXY to whatever yours is.
this worked for bundler. The .gemrc proxy setting only worked for gems.
thanks Jamie
Solution 5 - Ruby on-Rails
You can download the required gems locally with gem install and then bundle install. Not exactly neat, I know, but it does work.
Solution 6 - Ruby on-Rails
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
Solution 7 - Ruby on-Rails
Windows OS, run following command before execute bundle install
SET http_proxy=http://user:password@host:port
Solution 8 - Ruby on-Rails
Make sure your OS default http_proxy is already set up. If you're using Linux try the following command to know which proxy it's pointing to.
echo $http_proxy
In my Ubuntu OS, I set my http_proxy environment variable to my proxy server in ~/.bashrc
Solution 9 - Ruby on-Rails
$ 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.
ref :https://memset.wordpress.com/2010/10/14/bash-http_proxy-from-a-user-environment-to-sudo-one/
Solution 10 - Ruby on-Rails
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.
If you put the following in your ~/.gemrc it will work.
http_proxy: proxy-url:port
Replace the proxy-url:port with your proxy address and port. After I added that, I ran "bundle install" and everything ran as expected.
Solution 11 - Ruby on-Rails
To have command bundle install
work with proxy on windows do the following:
- 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.