Tuesday, February 27, 2007

How to Update Gems from Behind a Proxy

I have been trying to work out how to use install and update rails from behind a proxy that required authentication. The issue being that web browsers prompt you for your proxy login details. The command prompt on windows doesn't.

I finally got it working but it wasn't quite how the Gem FAQ stipulates, so I thought I would share it.

The Simple Solution

Execute the following command from the command prompt.

set HTTP_PROXY=http://[username]:[password]@[proxyserver]:[port]

Your gem commands should now work fine.

The Complex Solution

  • Get hold of the 'NTLM authorization Proxy Server' currently on source forge as ntlmaps.
  • Configure it so it known your login to the real proxy server. (you edit the server.cfg, but see gems faq page for details)
  • Set HTTP_PROXY as above but pointing to your new proxy server
  • If it still doesn't work, try passing your login credentials to the new proxy server.

Note: I tried the gem commands using the -p switch but most commands don't work properly. I was getting "ERROR: While executing gem ... (Errno::EBADF)"

Using the environment variable HTTP_PROXY instead fixed this.

6 comments:

agang sechaba said...

set http_proxy=http://username:password@proxy:port wouldn't work for me, because my proxy password was something like "P@ssw0rd", so yah, there you hae it. The @ sign in my password was the problem because I always used to end up with URI::InvalidURIError. Nevertheless, I called the technical guys and asked them to change my password since I can't change it myself. It works. Thanks

Anonymous said...

You may have to html encode your username and or password. The user name "F Bloggs" would have to be specified as "F%20Bloggs" (without the doublequoted of course.

Unknown said...

Something else you might want to consider is if you already have a http_proxy defined in your environment that the gem updater looks for uppercase HTTP_PROXY. So in your /etc/profile you would want to define the following:

http_proxy=http://{ipaddress}:{port}
HTTP_PROXY=http://{ipaddress}:{port}
https_proxy=http://{ipaddress}:{port}
HTTPS_PROXY=http://{ipaddress}:{port}
ftp_proxy=http://{ipaddress}:{port}
FTP_PROXY=http://{ipaddress}:{port}

export http_proxy HTTP_PROXY https_proxy HTTPS_PROXY ftp_proxy FTP_PROXY

In doing this it sets up all profiles with the proxy settings so the general users do not need to mess with their .bash_rc files in the home directories (if that is what they are using)

Im not a Linux expert, but this is what I do for my environments.

J

Nigel Thorne said...

Originally I was having his problem with a windows/dos environment. Thanks for the feedback though.

alexbaum said...

Thanks!!!

Anonymous said...

I had a similar problem, except my username was my email address, just substitute the @ for %40 (hex value of @) and it will work.

http://user%40mydomain.com:password@IP:8000

GitHub Projects