Monday, 8 October 2012

Install or update gems behind corporate firewall or proxy server

If you work with Ruby on Windows in a corporate environment, sooner or later, you will hit an error when you are trying to install or update Gems. In my case, I simply had to set a few environment variables and I was good to go. RubyGems uses the HTTP_PROXY, HTTP_PROXY_USER and HTTP_PASS by default so if you open up a command prompt and set these as follows, it will use them to find the proxy and authenticate you to your proxy server:

set HTTP_PROXY=http://pr.oxy.ip:port
set HTTP_PROXY_USER=domain\user.name
set HTTP_PASS=sUp3rS3curepAs$w0rd

Extra points: A reader sent me a comment that this will only work when the proxy is using basic authentication. If you're having trouble using this method then you can give ntlmaps a shot. It's basically a little bit of python magic that sets up a proxy on your localhost through which you can route traffic and it will handle the authentication with your proxy server for you.

2 comments:

  1. I normally URL encode the user and pass in HTTP_PROXY (ie http://user:pass@proxy:port) but I was having problems and found this post. Can you confirm whether to your knowledge it is HTTP_PASS or HTTP_PROXY_PASS? your snippet and post text do not agree.

    Cheers.

    ReplyDelete
  2. My bad Ben - I'm using HTTP_PASS as per the code snippet. Updating the post as we speak.....

    ReplyDelete