Use ruby bundler behind a proxy

How to install the ruby bundler behind a proxy with sudo.

To use ruby bundler behind a proxy, define the proxy host in env variables http_proxy and https_proxy.

For instance

export http_proxy=
export https_proxy=

However if you need to sudo, because you have no write permission on the ruby gems folder, sudo does not preserve the http_proxy env variable. Therefore add following line in /etc/sudoers

Defaults        env_keep = "http_proxy ftp_proxy"

before this line:

Defaults        env_reset

After this you can install the bundler gem.

tan@omega:~/sources/my-awesome-site$ sudo gem install bundler
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Installing ri documentation for bundler-1.14.6
Done installing documentation for bundler after 4 seconds
1 gem installed