Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use bundler behind a proxy?

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

like image 567
bioneuralnet Avatar asked Oct 06 '10 21:10

bioneuralnet


People also ask

Should bundler be in Gemfile?

In order to require gems in your Gemfile , you will need to call Bundler. require in your application. If some of your gems need to be fetched from a private gem server, this default source can be overridden for those gems.

What is bundled with in Gemfile lock?

Ruby apps will now have the `BUNDLED WITH` declaration in their `Gemfile. lock` removed after detecting Bundler version. The version listed in the BUNDLED WITH key of the Gemfile. lock is used by Heroku to detect what version of Bundler to use.


1 Answers

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% 
like image 81
ahmy Avatar answered Oct 24 '22 10:10

ahmy