Solution 1:

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:

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:

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:

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:

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