昨天在安装了Ruby 1.9.2 ,并且将其路径加入到Devkitconfig.yml中,并且使用ruby dk.rb install安装(不幸的是,没注意安装信息)。。但是依然无法构建native gem。于是重装Ruby,按照devkit的安装说明来安装。还是不正确。 Devkit的安装说明的第4步为Run Installation Scripts:

cd <DEVKIT_INSTALL_DIR> from Step 3 above.
ruby dk.rb init to generate the config.yml file to be used later in this Step. Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present).
edit the generated config.yml file to include installed Rubies not automagically discovered or remove Rubies you do not want to use the DevKit with.
[optional] ruby dk.rb review to review the list of Rubies to be enhanced to use the DevKit and verify the changes you made to it are correct.
finally, ruby dk.rb install to DevKit enhance your installed Rubies. This step installs (or updates) an operating_system.rb file into the relevant directory needed to implement a RubyGems pre_install hook and a devkit.rb helper library file into <RUBY_INSTALL_DIR>\lib\ruby\site_ruby. NOTE: you may need to use the --force option to update (with backup of the originals) the above mentioned files as discussed at the SFX DevKit upgrade FAQ entry.

在最后一步可知,安装Devkit其实就是更新了operating_system.rb文件,同时新建了devkit.rb文件。 在我的电脑上devkit.rb已经创建好(Devkit安装在D:/Ruby187/devkit目录下,其他电脑上的路径可能与我的不同):

view plaincopy to clipboardprint?

# enable RubyInstaller DevKit usage as a vendorable helper library 
unless ENV[‘PATH’].include?(‘d:\\Ruby187\\devkit\\mingw\\bin’) then 
  puts ‘Temporarily enhancing PATH to include DevKit…’ 
  ENV[‘PATH’] = ‘d:\\Ruby187\\devkit\\bin;d:\\Ruby187\\devkit\\mingw\\bin;’ + ENV[‘PATH’
end 

# enable RubyInstaller DevKit usage as a vendorable helper library
unless ENV['PATH'].include?('d:\\Ruby187\\devkit\\mingw\\bin') then
  puts 'Temporarily enhancing PATH to include DevKit...'
  ENV['PATH'] = 'd:\\Ruby187\\devkit\\bin;d:\\Ruby187\\devkit\\mingw\\bin;' + ENV['PATH']
end

在Ruby1.9.2中,有两个operating_system.rb文件,分别位于lib\ruby\site_ruby\1.9.1\rubygems\defaultslib\ruby\1.9.1\rubygems\defaults下,其内容相同:

view plaincopy to clipboardprint?

# :DK-BEG: missing DevKit/build tool convenience notice 
 
Gem.pre_install do |gem_installer| 
  unless gem_installer.spec.extensions.empty? 
    have_tools = %w{gcc make sh}.all? do |t| 
      system(“#{t} –version > NUL 2>&1”
    end 
 
    unless have_tools 
      raise Gem::InstallError,<<-EOT 
The ‘#{gem_installer.spec.name}’ native gem requires installed build tools. 
 
Please update your PATH to include build tools or download the DevKit 
from ‘http://rubyinstaller.org/downloads’and follow the instructions 
at ‘http://github.com/oneclick/rubyinstaller/wiki/Development-Kit’ 
EOT 
    end 
  end 
end 
# :DK-END: 

# :DK-BEG: missing DevKit/build tool convenience notice

Gem.pre_install do |gem_installer|
  unless gem_installer.spec.extensions.empty?
    have_tools = %w{gcc make sh}.all? do |t|
      system("#{t} --version > NUL 2>&1")
    end

    unless have_tools
      raise Gem::InstallError,<<-EOT
The '#{gem_installer.spec.name}' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
EOT
    end
  end
end
# :DK-END:

参考了我电脑上其他版本的Ruby(1.8.7-p334和1.8.7-p330,分别都只有一个operating_system.rb),在安装好Devkit之后,该文件应该为:

view plaincopy to clipboardprint?

Gem.pre_install do |i| 
  unless ENV[‘PATH’].include?(‘d:\\Ruby187\\devkit\\mingw\\bin’) then 
    puts ‘Temporarily enhancing PATH to include DevKit…’ 
    ENV[‘PATH’] = ‘d:\\Ruby187\\devkit\\bin;d:\\Ruby187\\devkit\\mingw\\bin;’ + ENV[‘PATH’
  end 
end 

Gem.pre_install do |i|
  unless ENV['PATH'].include?('d:\\Ruby187\\devkit\\mingw\\bin') then
    puts 'Temporarily enhancing PATH to include DevKit...'
    ENV['PATH'] = 'd:\\Ruby187\\devkit\\bin;d:\\Ruby187\\devkit\\mingw\\bin;' + ENV['PATH']
  end
end

在修改了lib\ruby\1.9.1\rubygems\defaults\operating_system.rb之后,构建native gem时,依然找不到Devkit;但修改lib\ruby\site_ruby\1.9.1\rubygems\defaults\operating_system.rb 后(不修改lib\ruby\1.9.1\rubygems\defaults\operating_system.rb),便可以成功构建。 所以,如何确认Devkit是否安装成功呢? 答:检查devkit.rboperating_system.rb 文件,其内容应该和上面的内容相同;否则,安装不成功。 可以手动更改这两个文件为上面的形式(好像也可以删除这两个文件,然后使用ruby dk.rb install命令,此时会创建 – 未验证)。在使用ruby dk.rb install时候,需要注意安装信息或警告,如果某些文件已经存在,可能会跳过。 但是,为什么在看似“正常”的安装步骤下,为什么没能安装好Devkit? 我没有找到原因;或许我的某个步骤有问题。我发现,虽然我安装的是1.9.2,但是却被安装在了lib\ruby\1.9.1目录下,官方解释说:

This version is a “library compatible version.” Ruby 1.9.2 is almost 1.9.1 compatible, so the library is installed in the 1.9.1 directory.