Elia Schito

Gems through the proxy (or the «undefined method `[]=’» error)

In Gems, Gems proxy, Rails, Ruby, Ruby on Rails, Ruby snippets, Tricks, Tutorials on July 18, 2007 at 7:37 pm

Ok, if you have tried to work with the gem command through a proxy, like gem install rails -p http://proxy.ccci.org:8080 you surely incurred in the following error:

ERROR: While executing gem ... (NoMethodError)
undefined method `[]=' for Gem::ConfigFile

The solution is barely to patch the Gem::ConfigFile class adding the following method:

def []=(key, value)
  @hash[key.to_s]=value
end

(I added it at line 72)
The only hard part colud be to locate that class inside the ruby libraries… don’t worry here’s the path:

ruby/site_ruby/1.8/rubygems/config_file.rb

this is (obviously) relative to the ruby folder, on my MacBook it is located in: /opt/local/lib/

Update: Translation in Portuguese

Update/2: Gems Proxy under windows

  1. Thank you, this was very helpful.

  2. Thank you very much.

  3. Thank you, and thanks for the search engine I used, forgot the name.

  4. Thank you, I’ve been searching for hours for exactly this fix.

    Any chance of this being better publicised? What’s causing this problem?

  5. […] (encontrei essa solução aqui: Gems through the proxy (or the «undefined method `[]=’» error) ) […]

  6. Thank you so much !!!!

  7. wtf this is pretty insane. How in the name of god did they manage to NOT fix an error like this? Anyway, thankss a lot for the fix!!

  8. Thanks a ton, this was driving me nuts!

  9. Works fine! Thanks!

  10. Thank you, this has helped me twice now! :)

  11. Thanks!

  12. I hope this issue is fixed in 1.8.7. (oneclickinstaller… too lazy :P). Thanks a lot!

  13. Thanks! This helped me quite a bit.

  14. thanks buddy it works but i have started to get another error. Do you have solution for this also !!!

    ERROR: While executing gem … (RuntimeError)
    Error instaling watir:
    watir requires win32-process >= 0.5.5

  15. It seems that you need to install the win32-process gem with a version >= 0.5.5

    try “gem list -l” to look at the gem you have already installed on your pc, or retry installing watir with the “–include-dependencies” option

  16. Thanks for this!

  17. Thanks for this.. You rock

  18. Thanks a lot! Can’t understand why this is still not fixed in the mainstream distribution.

  19. Hi, first thanks. Second, when I try to run this command:
    gem update –system -p http://myproxy:8080

    I get this error:
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:37:in `[]’: wrong number of arguments (1 for 2) (ArgumentError) from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:37:in `do_configuration’

    Ideas?

  20. Thanks a lot.

    Darryl wrote:
    I get this error:
    c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:37:in `[]‘: wrong number of arguments (1 for 2) (ArgumentError) from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:37:in `do_configuration&#8217

    To fix this error don’t move the old lines.

    Here are the correct lines in config_file.rb

    # The name of the configuration file.
    def config_file_name
    @config_file_name || Gem.config_file
    end

    # Return the configuration information for +key+.
    def [](key)
    @hash[key.to_s]
    end

    def []=(key, value)
    @hash[key.to_s]=value
    end

    private…

  21. while trying gem update –system -p http://172.17.10.22:8080 am getting the following error..

    C:\>gem update –system -p http://172.17.10.22:8080
    Updating RubyGems…
    ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)
    A socket operation was attempted to an unreachable network. – connect(2)(Err
    no::ENETUNREACH)
    can any one help on this issue..

  22. Thank you. Worked like a charm! :)

  23. Thanks, that works fine !

  24. Thanks, great work. In case anyone needs to know where the default windows (at least XP) location of the ruby file you need to find, it is in C:\ruby\lib\ruby\site_ruby\1.8\rubygems

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: