54

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...)

bioneuralnet
  • 5,255
  • 1
  • 23
  • 30
  • Hi, dont suppose you got this working? I seem to have the same error on OSX :( – Chris Kimpton Jan 19 '11 at 13:29
  • No, I've never gotten it working. I have since stripped out Bundler from my app and am loading gems manually in config/application.rb. I can hardly tell the difference. – bioneuralnet Feb 02 '11 at 16:25
  • Why isn't this working? I have the same issue over Debian. – TuteC Feb 28 '11 at 21:46
  • I am also facing this issue. gem works http_proxy is set in my .profile and .gemrc, as explained in the original post On OSX, ruby 1.8.7, rubygems 1.3.7 Any ideas would be welcome :) – user537339 Dec 21 '10 at 04:07

11 Answers11

77

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%
ahmy
  • 3,777
  • 4
  • 26
  • 36
  • 1
    Good guess, but that's not it either. – bioneuralnet Dec 23 '10 at 20:12
  • 1
    As of (at least) bundler 1.0.12 this seems to work. Perhaps they fixed something? – bioneuralnet Sep 16 '11 at 14:53
  • 8
    it worked for me in windows box, by doing exactly same thing with "SET" command , eg `SET http_proxy=http://user:password@host:port ` and worked in cygwin too :) – Vh24 Apr 20 '12 at 15:40
  • 1
    ahmy's answer is the correct one. But if your username or password include special characters such as "" (others may cause problems as well) gem will not work. Make sure to remove any of these characters (by changing your password/username) then export again. If anyone has a workaround for these characters please reply as well. – cameleon Oct 08 '12 at 22:12
  • 1
    do no forget to set https_proxy – user831217 Feb 12 '15 at 11:25
  • 1
    "by default sudo does not preserve http proxy." - Really important note. :) Thank you. – Gergely Bacso Oct 07 '15 at 08:47
  • It worked for me on openSUSE Leap 15.0, with Ruby v2.5.0, gem v2.7.3, and Bundler v1.16.1. I've made a shell script that does `export http_proxy=...` and `export https_proxy=...` before invoking `bundle install`. As @user831217 pointed out on another comment, don't forget to set `https_proxy` too. – Antônio Medeiros Nov 12 '18 at 11:52
15

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

Jarl
  • 2,771
  • 4
  • 22
  • 30
5

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
coorasse
  • 4,908
  • 1
  • 30
  • 43
5

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

Jamie.Good
  • 351
  • 2
  • 6
  • 4
    Instead of doing it on the Environment, I just added it before calling bundle, using `SET HTTP_PROXY=http://username:password@www.proxy.com` – Montolide May 06 '13 at 17:34
  • 1
    i would prefer more flexible and securable way: 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 – vladimir Aug 25 '15 at 11:31
3

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
vladimir
  • 11,406
  • 2
  • 30
  • 53
3

You can download the required gems locally with gem install and then bundle install. Not exactly neat, I know, but it does work.

matttyg
  • 31
  • 3
1

Windows OS, run following command before execute bundle install

SET http_proxy=http://user:password@host:port
Jerry Z.
  • 1,961
  • 2
  • 21
  • 28
0
$ 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/

Pradeep Bihani
  • 111
  • 2
  • 6
0

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

rasyadi
  • 11
  • 1
0

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.

grayman
  • 1
  • 2
0

To have command bundle install work with proxy on windows do the following:

  1. Edit file .gemrc. Open windows command line and type: notepad %userprofile%\.gemrc .
  2. 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 .
  3. Close the file .gemrc with saving it.