When trying to run a gem command from behind a proxy you may have the problem that although HTTP_PROXY is defined in your environment when you run the gem command with sudo it does not pick up the proxy setting.

This is due to the fact that the sudo command runs in another shell which is initialized differently and is not passed your environment variables. What you need to do to get it to work is run (replacing the capitals with your variables):

sudo gem install --http-proxy http://$HOST:$PORT $GEM_NAME

There are lots of other ways to achieve this, for example other ways to pass environmental variables to sudo but I find that this is simple and useful if you use a laptop on different networks and don't always want to have a proxy configured. You could also create an aliases for this command and use them when you need a given proxy.

Filed under: languages, tools


There are no comments.