星期六, 7月 07, 2007

Problems while installing RoR on OpenBSD

While installing ruby from ports (currently 1.8.5) on my OpenBSD 4.1 boxes, I will always get an error as follows:

.... failed to allocate memory (NoMemoryError)

 So, I tried to install ruby 1.8.6 and rubygems 0.9.4 from source tarballs instead and it can be done successfully w/o errors. But after that, another error showed when i tried to install rails:

Bulk updating Gem source index for: http://gems.rubyforge.org
/usr/local/lib/ruby/1.8/yaml.rb:133: [BUG] Segmentation fault
ruby 1.8.6 (2007-03-13) [i386-openbsd4.1]

Abort

After some googling around, I found this solution and it works for me.

You have to modify the file /usr/local/lib/ruby/site_ruby/1.8/rubygems/sources_index.rb, replace the convert_specs method with the following one:

def convert_specs(yaml_spec)
      specs = Cache.new

      nl = 0
      yaml_spec.each do |line|
        nl += 1
      end

      notify_percent = 15
      nl_till_rollover = nl_for_x_percent = nl / notify_percent
      p = 0.0

      state = :scan
      gem_yaml = ''
      yaml_spec += "\n  DONE" # so that the last gem is added

      yaml_spec.each do |line|
        if nl_till_rollover == 0 && nl > 100000
          p += 100.0 / notify_percent
          nl_till_rollover = nl_for_x_percent
          puts "#{p.to_i}%"
        end
        nl_till_rollover -= 1

        if state == :scan && line =~ /^  \S/
          gem_yaml = line
          state = :copy
        elsif state == :copy && line =~ /^  \S/
          spec = YAML.load(gem_yaml).values[0]
          specs.add_spec spec
          # keep going
          gem_yaml = line
        elsif state == :copy
          gem_yaml += line
        end
      end

      specs
    end

Then, you can run "gem i rails -y" again, but it will show:

Bulk updating Gem source index for: http://gems.rubyforge.org
6%
13%
20%
26%
33%
40%
46%
53%
59%
66%
73%
80%
86%
93%
100%
ERROR:  While executing gem ... (Gem::GemNotFoundException)
    Could not find rails (> 0) in any repository

 

That's alright, just run AGAIN and it will be done successfully. (I don't know why I have to run it twice....)

 

Technorati Tags: , , , ,

沒有留言: