ChatGPT解决这个技术问题 Extra ChatGPT

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

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`'
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

t
the Tin Man

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

Install/Run Fiddler from www.fiddler2.com Run gem: $ gem install --http-proxy http://localhost:8888 $gem_name


Worked a treat, much easier than ntlmaps and cntlm.
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.
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.
Works on Windows 10
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
t
the Tin Man

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.


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.
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)
@spoulson You need to URI encode the backslash if you need the domain, e.g. http ://domain%5Cuserid@server:port.
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.
By the way, if your password contains special symbols, you should urlencode them. E.g. replace @ with %40 etc
t
the Tin Man

This totally worked:

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

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]
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/jekyll-3.0.0.gemspec.rz). This worked for me with gem install --http-proxy http://127.0.0.1:8580 jekyll
I added an alias to my bash profile: alias geminstall='gem install --http-proxy ${http_proxy}' to make my life easier.
J
Jason Navarrete

I've been using cntlm (http://cntlm.sourceforge.net/) at work. Configuration is very similar to ntlmaps.

gem install --http-proxy http://localhost:3128 _name_of_gem_

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


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!
Works perfectly on windows as well. Thanks!
t
the Tin Man

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.


Got thru installation by replacing the proxy part to username:password@proxy_ip:proxyport
I had to add the proxy_ip that is used for https connections in order to work! Great :D (gem version 2.0.14)
r
riemann

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.


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
H
HomTom

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

t
the Tin Man

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=some.proxy.com
set HTTP_PROXY_USER=user
set HTTP_PROXY_PASS=password

The user:password@ 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.


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.
S
Shantonu

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

When adding an answer to an older question with existing answers it is useful to explain what your answer adds that is new.
to specify command directly without detail reading all details (quick answers)
and, setting environment variable is not an option for everybody (when you do only one time update)
Please add all explanation to the answer itself, not to the comment section
Don't worry, this answer is the exact information I was looking for, thank you.
C
Christian F

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:

http://blog.byscripts.info/2011/04/bypass-a-proxy-with-ssh-tunnel-and-tsocks-under-ubuntu/

Despite being written for Ubuntu the procedure should be applicable for all Unix based machines. An alternative to tsocks for Windows is FreeCap (http://www.freecap.ru/eng/). A viable SSH client on windows is called putty.


I found the article in my backups and just re-published it with the same URL.
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.
佚名

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 http://cntlm.awk.cz/, but that times out. A search on sourceforge turns up this link, which does work: http://sourceforge.net/projects/cntlm/

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.


C
Csa77

A workaround is to install http://web.archive.org/web/20060913093359/http://apserver.sourceforge.net:80/ 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 main.py

Run Gems: gem install—http-proxy http://localhost:5865/ library


Read in a google group that 'apserver' is now 'NTLM Authorization Server'; shame that searching for the former doesn't redirect to that latter.
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?
@Matrich as per Darren's comment. apserver is now renamed and found here: ntlmaps.sourceforge.net
t
the Tin Man

I am working behind a proxy and just installed SASS by downloading directly from http://rubygems.org.

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.


t
the Tin Man

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.


t
the Tin Man

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

export http_proxy=http://${proxy.host}:${port}
export https_proxy=http://${proxy.host}:${port}

and then try:

gem install ${gem_name}

m
moonpatrol

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

http://www.stuartellis.eu/articles/installing-ruby/


Site doesn't exist anymore!
Q
Qi Luo

If you want to use SOCKS5 proxy, you may try rubygems-socksproxy https://github.com/gussan/rubygems-socksproxy.

It works for me on OSX 10.9.3.


A
ArNumb

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


t
the Tin Man

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.

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

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

http://proxy-server-name

Or more complex as others have pointed out

http://username:password@proxy-server-name:port-number

M
Mike Campbell

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

Install socksify with gem install socksify (you'll need to be able to do this step without proxy, at least) Copy your existing gem exe cp $(command which gem) /usr/local/bin/proxy_gem Open it in your favourite editor and add this at the top (after the shebang) require 'socksify' if ENV['SOCKS_PROXY'] require 'socksify' host, port = ENV['SOCKS_PROXY'].split(':') TCPSocket.socks_server = host || 'localhost' TCPSocket.socks_port = port.to_i || 1080 end Set up your tunnel ssh -D 8123 -f -C -q -N user@proxy Run your gem command with proxy_gem SOCKS_PROXY=localhost:8123 proxy_gem push mygem