Ubuntu – Can’t install gems from behind proxy


I'm running 12.04 in a VM, and I am behind a corporate proxy.

I've got the environment variables set (tried both all lower and all upper case for [http|https|ftp]_proxy, as well as not specifying the user:pass but setting http_proxy_[user|pass])

I can access the web via curl/wget, and I have also gotten apt to use my proxy settings.

But I have been unable to get gem to install, or even list, any remote gems.

When I do try, I get the following:

$ sudo gem install hiera
ERROR:  Could not find a valid gem 'hiera' (>= 0) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNREFUSED: Connection refused - connect(2) (http://rubygems.org/latest_specs.4.8.gz)


$ sudo gem list -r


ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNREFUSED: Connection refused - connect(2) (http://rubygems.org/latest_specs.4.8.gz)

I did some searching on StackOverflow and have tried everything that did not require setting up a VPN or tunnel or external programs.

Is there something I am missing, or something about the env variables I have wrong?


Forgot to mention, I am able to download gems from my host workstation and install them that way, but I'd prefer to be able to install directly if at all possible. It's a hassle, especially when there are a lot of deps involved.

Also, for what it is worth:
$ gem –version

Best Answer

The environment is not preserved when using sudo, so the setting of the http_proxy variable alone is ineffective. You need to export the http_proxy variable and then run sudo with the option -E

export http_proxy=...
sudo -E gem list -r