How do I update Ruby Gems from behind a Proxy (ISA-NTLM)


The firewall I'm behind is running Microsoft ISA server in NTLM-only mode. Hash anyone have success getting their Ruby gems to install/update via Ruby SSPI gem or other method?

... or am I just being lazy?

Note: rubysspi-1.2.4 does not work.

This also works for "igem", part of the IronRuby project

This question is tagged with ruby proxy rubygems ironruby

~ Asked on 2008-08-07 05:21:16

20 Answers


I wasn't able to get mine working from the command-line switch but I have been able to do it just by setting my HTTP_PROXY environment variable. (Note that case seems to be important). I have a batch file that has a line like this in it:


I set the four referenced variables before I get to this line obviously. As an example if my username is "wolfbyte", my password is "secret" and my proxy is called "pigsy" and operates on port 8080:

SET HTTP_PROXY=http://wolfbyte:[email protected]:8080

You might want to be careful how you manage that because it stores your password in plain text in the machine's session but I don't think it should be too much of an issue.

~ Answered on 2008-08-07 05:49:00


For the Windows OS, I used Fiddler to work around the issue.

  1. Install/Run Fiddler from
  2. Run gem:

    $ gem install --http-proxy http://localhost:8888 $gem_name

~ Answered on 2010-11-15 17:45:16


This totally worked:

gem install --http-proxy http://COMPANY.PROXY.ADDRESS $gem_name

~ Answered on 2012-03-26 03:35:24


I've been using cntlm ( at work. Configuration is very similar to ntlmaps.

Works great, and also allows me to connect my Ubuntu box to the ISA proxy.

Check out for more information

~ Answered on 2008-08-31 21:59:45


I tried some of these solutions, and none of them worked. I finally found a solution that works for me:

gem install -p http://proxy_ip:proxy_port rails

using the -p parameter to pass the proxy. I'm using Gem version 1.9.1.

~ Answered on 2012-08-01 23:32:44


Create a .gemrc file (either in /etc/gemrc or ~/.gemrc or for example with chef gem in /opt/chef/embedded/etc/gemrc) containing:

http_proxy: http://proxy:3128

Then you can gem install as usual.

~ Answered on 2015-12-22 09:14:35


This solved my problem perfectly:

gem install -p http://proxy_ip:proxy_port compass

You might need to add your user name and password to it:

gem install -p http://[username]:[password]@proxy_ip:proxy_port compass

~ Answered on 2014-04-09 08:48:40


If you are having problems getting authenticated through your proxy, be sure to set the environment variables in exactly the format below:

set HTTP_PROXY_PASS=password

The user:[email protected] syntax doesn't seem to work and there are also some badly named environment variables floating around on Stack Overflow and various forum posts.

Also be aware that it can take a while for your gems to start downloading. At first I thought it wasn't working but with a bit of patience they started downloading as expected.

~ Answered on 2012-02-21 17:26:31


I tried all the above solutions, however none of them worked. If you're on linux/macOS i highly suggest using tsocks over an ssh tunnel. What you need in order to get this setup working is a machine where you can log in via ssh, and in addition to that a programm called tsocks installed.

The idea here is to create a dynamic tunnel via SSH (a socks5 proxy). We then configure tsocks to use this tunnel and to start our applications, in this case:

tsocks gem install ...

or to account for rails 3.0:

tsocks bundle install

A more detailed guide can be found under:

Despite being written for Ubuntu the procedure should be applicable for all Unix based machines. An alternative to tsocks for Windows is FreeCap ( A viable SSH client on windows is called putty.

~ Answered on 2011-09-06 05:04:51


Quick answer : Add proxy configuration with parameter for both install/update

gem install --http-proxy http://host:port/ package_name

gem update --http-proxy http://host:port/ package_name

~ Answered on 2019-06-17 18:50:23


Posts abound regarding this topic, and to help others save hours of trying different solutions, here is the final result of my hours of tinkering.

The three solutions around the internet at the moment are: rubysspi apserver cntlm

rubysspi only works from a Windows machine, AFAIK, as it relies on the Win32Api library. So if you are on a Windows box trying to run through a proxy, this is the solution for you. If you are on a Linux distro, you're out of luck.

apserver seems to be a dead project. The link listed in the posts I've seen lead to 404 page on sourceforge. I search for "apserver" on sourceforge returns nothing.

The sourceforge link for cntlm that I've seen redirects to, but that times out. A search on sourceforge turns up this link, which does work:

After downloading and configuring cntlm I have managed to install a gem through the proxy, so this seems to be the best solution for Linux distros.

~ Answered on 2009-03-10 10:33:12


A workaround is to install on your local machine, configure it and run gems through this proxy.

  • Install: Just download apserver 097 (and not the experimental 098!) and unpack.
  • Configure: Edit the server.cfg file and put the values for your MS proxy in PARENT_PROXY and PARENT_PROXY_PORT. Enter the values for DOMAIN and USER. Leave PASSWORD blank (nothing after the colon) – you will be prompted when launching it.
  • Run apserver: cd aps097; python
  • Run Gems: gem install—http-proxy http://localhost:5865/ library

~ Answered on 2008-08-07 05:25:54


I am working behind a proxy and just installed SASS by downloading directly from

I then ran sudo gem install [path/to/downloaded/gem/file]. I cannot say this will work for all gems, but it may help some people.

~ Answered on 2012-11-26 11:23:00


This worked for me in a Windows box:

set HTTP_PROXY=http://server:port
set HTTP_PROXY_USER=username
set HTTP_PROXY_PASS=userparssword
set HTTPS_PROXY=http://server:port
set HTTPS_PROXY_USER=username
set HTTPS_PROXY_PASS=userpassword

I have a batch file with these lines that I use to set environment values when I need it.

The trick, in my case, was HTTPS_PROXY sets. Without them, I always got a 407 proxy authentication error.

~ Answered on 2015-01-13 11:35:47


If you are on a *nix system, use this:

export http_proxy=http://${}:${port}
export https_proxy=http://${}:${port}

and then try:

gem install ${gem_name}

~ Answered on 2013-10-25 17:50:45


rubysspi-1.3.1 worked for me on Windows 7, using the instructions from this page:

~ Answered on 2011-11-04 07:46:25


If you want to use SOCKS5 proxy, you may try rubygems-socksproxy

It works for me on OSX 10.9.3.

~ Answered on 2014-06-06 16:52:33


If behind a proxy, you can navigate to Ruby downloads, click on Download, which will download the specified update ( or Gem ) to a desired location.

Next, via Ruby command line, navigate to the downloaded location by using : pushd [directory]

eg : pushd D:\Setups

then run the following command: gem install [update name] --local

eg: gem install rubygems-update --local.

Tested on Windows 7 with Ruby update version 2.4.1.

To check use following command : ruby -v

~ Answered on 2014-08-11 13:27:13


Rather than editing batch files (which you may have to do for other Ruby gems, e.g. Bundler), it's probably better to do this once, and do it properly.

On Windows, behind my corporate proxy, all I had to do was add the HTTP_PROXY environment variable to my system.

  1. Start -> right click Computer -> Properties
  2. Choose "Advanced System Settings"
  3. Click Advanced -> Environment Variables
  4. Create a new System variable named "HTTP_PROXY", and set the Value to your proxy server
  5. Reboot or log out and back in again

Depending on your authentication requirements, the HTTP_PROXY value can be as simple as:


Or more complex as others have pointed out

http://username:[email protected]:port-number

~ Answered on 2014-05-16 06:27:13


for anyone tunnelling with SSH; you can create a version of the gem command that uses SOCKS proxy:

  1. Install socksify with gem install socksify (you'll need to be able to do this step without proxy, at least)
  2. Copy your existing gem exe

    cp $(command which gem) /usr/local/bin/proxy_gem
  3. Open it in your favourite editor and add this at the top (after the shebang)

    require 'socksify'
      require 'socksify'
      host, port = ENV['SOCKS_PROXY'].split(':')
      TCPSocket.socks_server = host || 'localhost'
      TCPSocket.socks_port = port.to_i || 1080
  4. Set up your tunnel

    ssh -D 8123 -f -C -q -N [email protected]
  5. Run your gem command with proxy_gem

    SOCKS_PROXY=localhost:8123 proxy_gem push mygem

~ Answered on 2020-04-03 14:10:52

Most Viewed Questions: