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

257,054

Solution 1

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:

SET HTTP_PROXY=http://%USER%:%PASSWORD%@%SERVER%:%PORT%

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:secret@pigsy: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.

Solution 2

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

  1. Install/Run Fiddler from www.fiddler2.com
  2. Run gem:

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

Solution 3

This totally worked:

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

Solution 4

I've been using cntlm (http://cntlm.sourceforge.net/) 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 http://cntlm.wiki.sourceforge.net/ for more information

Solution 5

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.

Share:
257,054

Related videos on Youtube

scoopr
Author by

scoopr

Disciple, Husband, Father, Brother, Son... Programmer

Updated on June 19, 2020

Comments

  • scoopr
    scoopr about 4 years

    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

    • iconoclast
      iconoclast about 12 years
      I've gotten rubysspi to work, but there's a lot of fiddling required. If you want to use it from a Git Bash shell, you'll need an alias added to your .bashrc file, such as this: alias gem='ruby -rspa `which gem`'
    • kayleeFrye_onDeck
      kayleeFrye_onDeck about 8 years
      If you have proxy issues after doing the steps in most of these answers, try making sure sudo has access to your environment variables by adding the -E switch, e.g., sudo -E doSomething
  • spoulson
    spoulson about 15 years
    It seems 'gem' fails to recognize backslashes in the proxy string, whether by http_proxy env var or --http-proxy argument. e.g. from my Ubuntu box --http-proxy http ://domain\\userid@server:port gives me the error: "invalid argument: --http-proxy ..."; Fortunately, my proxy server didn't require the domain specification and gem worked without it.
  • squillman
    squillman about 15 years
    ISA lets the admin specify a default domain to authenticate against. You can try to leave out the domain and just use your username like spoulson suggests. If your ISA admin has specified said default domain and your useraccount is in that domain, this should work for you (assuming there are no blocking rules on the firewall)
  • Gishu
    Gishu almost 15 years
    Thanks this worked! Wonder why it didnt work when i tried the -p and --http-proxy command line args. It seems like the env var is what works.
  • Darren Bishop
    Darren Bishop almost 14 years
    Read in a google group that 'apserver' is now 'NTLM Authorization Server'; shame that searching for the former doesn't redirect to that latter.
  • Matrich
    Matrich almost 14 years
    Hi Jarin, I went to the link you provided in your comment and couldn't find that download. Is there any way I can download it from anywhere else?
  • Ian G
    Ian G over 13 years
    @spoulson You need to URI encode the backslash if you need the domain, e.g. http ://domain%5Cuserid@server:port.
  • atomicules
    atomicules over 13 years
    @Matrich as per Darren's comment. apserver is now renamed and found here: ntlmaps.sourceforge.net
  • atomicules
    atomicules over 13 years
    Worked a treat, much easier than ntlmaps and cntlm.
  • Polaris878
    Polaris878 about 13 years
    This worked for me. Note that Fiddler isn't needed in all situations. Just gem install --http-proxy http://COMPANY.PROXY.ADDRESS $gem_name is all that was needed for me.
  • Ed Manet
    Ed Manet almost 13 years
    FYI, in Windows, you can add the set http_proxy line to gem.bat so that you don't have to remember to set the proxy each time.
  • Konrads
    Konrads almost 12 years
    This is the least painful way of all tried. On Ubuntu/Debian, I do apt-get install cntlm, edit config and then export http_proxy="localhost:3128". Works!
  • egerardus
    egerardus over 11 years
    This is the most up to date answer, it works with windows also. I had to add my username and password though: gem install --http-proxy http://[user]:[password]@[server]:[port]
  • Stef
    Stef over 11 years
    awesome mate, been getting mad here, trying to figure out why it works fine in my Ubuntu virtual machine and not on Windows. Thanks heaps
  • Gary Tsui
    Gary Tsui almost 11 years
    Got thru installation by replacing the proxy part to username:password@proxy_ip:proxyport
  • raycarr
    raycarr over 10 years
    Taking Benjamin Wootton's tip worked out great on my Windows 7 laptop connected to the corporate LAN. In the command line window at the DOS prompt I set the HTTP_PROXY as http: // localhost : 8888 (ignore the spaces) and then used my LAN username and Password for HTTP_PROXY_USER and HTTP_PROXY_PASS respectively.
  • Byscripts
    Byscripts over 10 years
    I found the article in my backups and just re-published it with the same URL.
  • Subrat Pattnaik
    Subrat Pattnaik over 9 years
    Works perfectly on windows as well. Thanks!
  • madlymad
    madlymad over 8 years
    I had to add the proxy_ip that is used for https connections in order to work! Great :D (gem version 2.0.14)
  • Majid Fouladpour
    Majid Fouladpour over 8 years
    I could not install jekyll and kept getting SSL_connect SYSCALL returned=5 errno=0 state=unknown state (https://rubygems.global.ssl.fastly.net/quick/Marshal.4.8/je‌​kyll-3.0.0.gemspec.r‌​z). This worked for me with gem install --http-proxy http://127.0.0.1:8580 jekyll
  • PJP
    PJP over 8 years
    The URL is still not available. When providing a link to an off-site, non-Stack Exchange site, summarize the salient parts here and give credit to that site. That way, when the link breaks, the important part is still here.
  • bgStack15
    bgStack15 over 8 years
    I added an alias to my bash profile: alias geminstall='gem install --http-proxy ${http_proxy}' to make my life easier.
  • Suriyaa
    Suriyaa about 8 years
    Site doesn't exist anymore!
  • Andrey Regentov
    Andrey Regentov almost 8 years
    By the way, if your password contains special symbols, you should urlencode them. E.g. replace @ with %40 etc
  • Alek Davis
    Alek Davis over 7 years
    On Windows 7, --http-proxy flag must go after the gem name, e.g. gem install <gemaname> --http-proxy yourproxy.address;port. Otherwise, it will complain about an invalid command-line switch.
  • ggiunta
    ggiunta over 7 years
    Works on Windows 10
  • Joseph
    Joseph about 6 years
    This is what worked for me behind a corporate proxy. No fiddler needed. For example to install jekyll gem just run: sudo gem install jekyll --http-proxy=http://web-proxy.company.com:8080
  • Jason Aller
    Jason Aller about 5 years
    When adding an answer to an older question with existing answers it is useful to explain what your answer adds that is new.
  • Shantonu
    Shantonu about 5 years
    to specify command directly without detail reading all details (quick answers)
  • Shantonu
    Shantonu about 5 years
    and, setting environment variable is not an option for everybody (when you do only one time update)
  • Nico Haase
    Nico Haase about 5 years
    Please add all explanation to the answer itself, not to the comment section
  • DependencyHell
    DependencyHell over 4 years
    In case it is working using --http-proxy but not with a .gemrc file, it may come from the sudo configuration. I had to check /etc/sudoers file to add : Defaults env_keep = "http_proxy ftp_proxy" before : Defaults env_reset
  • doublespaces
    doublespaces over 2 years
    Don't worry, this answer is the exact information I was looking for, thank you.