Wednesday, June 1, 2011

Installing Rails From Behind A Corporate Proxy

I had a little extra time on my hands and wanted to experiment with Ruby on Rails. The articles that I had read raved about how easy it was to set up the development environment using RubyGems.

Latest versions of Ruby and RubyGems were downloaded and installed without incident. Where I ran into a big problem was installing Rails and its dependencies. Initially I tried to run "gem install rails" but the operation failed due to proxy authentication issues, and this is a well known limitation.

I thought that I would manually download and install the gems but this would have taken hours. As usual, a StackOverflow post provided the inspiration to use CNTLM.

Initially I couldn't get CNTLM to authenticate properly because I didn't know the correct authentication type. The CNTLM manual indicated that there is a switch ("-M") that will test various authentication types using "magic NTLM dialect detection" (!). Using "cntlm -M http://www.google.com" revealed the correct mode that I should use. After making the change in cntlm.ini and restarting the CNTLM service I was able to successfully install rails using the following command:

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

Here's a sampling of the errors that I experienced as well as a successful download:

C:\Ruby192\bin>gem install rails --http-proxy http://localhost:3128
C:\Ruby192\bin>gem install rails
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    too many connection resets (http://rubygems.org/gems/abstract-1.0.0.gem)

C:\Ruby192\bin>gem install rails --http-proxy http://localhost:3128
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    bad response Not Found 404 (http://rubygems.org/gems/abstract-1.0.0.gem)

C:\Ruby192\bin>gem install rails --http-proxy http://localhost:3128
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    bad response Proxy Authorization Required 407 (http://rubygems.org/gems/abstract-1.0.0.gem)

C:\Ruby192\bin>gem install rails --http-proxy http://localhost:3128
Fetching: abstract-1.0.0.gem (100%)
WARNING: abstract-1.0.0 has an invalid nil value for @cert_chain
Fetching: erubis-2.6.6.gem (100%)
Fetching: actionpack-3.0.7.gem (100%)
Fetching: arel-2.0.10.gem (100%)
Fetching: activerecord-3.0.7.gem (100%)
Fetching: activeresource-3.0.7.gem (100%)
Fetching: mime-types-1.16.gem (100%)
Fetching: polyglot-0.3.1.gem (100%)
Fetching: treetop-1.4.9.gem (100%)
Fetching: mail-2.2.19.gem (100%)
Fetching: actionmailer-3.0.7.gem (100%)
Fetching: thor-0.14.6.gem (100%)
Fetching: railties-3.0.7.gem (100%)
Fetching: rails-3.0.7.gem (100%)
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.7
Successfully installed arel-2.0.10
Successfully installed activerecord-3.0.7
Successfully installed activeresource-3.0.7
Successfully installed mime-types-1.16
Successfully installed polyglot-0.3.1
Successfully installed treetop-1.4.9
Successfully installed mail-2.2.19
Successfully installed actionmailer-3.0.7
Successfully installed thor-0.14.6
Successfully installed railties-3.0.7
Successfully installed rails-3.0.7
14 gems installed
Installing ri documentation for abstract-1.0.0...
Installing ri documentation for erubis-2.6.6...
Installing ri documentation for actionpack-3.0.7...
Installing ri documentation for arel-2.0.10...
Installing ri documentation for activerecord-3.0.7...
Installing ri documentation for activeresource-3.0.7...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for polyglot-0.3.1...
Installing ri documentation for treetop-1.4.9...
Installing ri documentation for mail-2.2.19...
Installing ri documentation for actionmailer-3.0.7...
Installing ri documentation for thor-0.14.6...
Installing ri documentation for railties-3.0.7...
Installing ri documentation for rails-3.0.7...
Installing RDoc documentation for abstract-1.0.0...
Installing RDoc documentation for erubis-2.6.6...
Installing RDoc documentation for actionpack-3.0.7...
Installing RDoc documentation for arel-2.0.10...
Installing RDoc documentation for activerecord-3.0.7...
Installing RDoc documentation for activeresource-3.0.7...
Installing RDoc documentation for mime-types-1.16...
Installing RDoc documentation for polyglot-0.3.1...
Installing RDoc documentation for treetop-1.4.9...
Installing RDoc documentation for mail-2.2.19...
Installing RDoc documentation for actionmailer-3.0.7...
Installing RDoc documentation for thor-0.14.6...
Installing RDoc documentation for railties-3.0.7...
Installing RDoc documentation for rails-3.0.7...

No comments:

Post a Comment