安装gollum提示Failed to build gem native extension的解决

gollum是GitHub的一个开源Wiki引擎,老蔡准备用来写代码文档,结果安装就出错了。

直接sudo gem install gollum来安装gollum会提示错误

ERROR: Error installing gollum:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from extconf.rb:1:in `

Gem files will remain installed in /var/lib/gems/1.9.1/gems/posix-spawn-0.3.6 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/posix-spawn-0.3.6/ext/gem_make.out

从git://github.com/gollum/gollum.git源码bundle install也会提示

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb                                                                                                   

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’: cannot load such file – mkmf (LoadError)

Gem files will remain installed in /home/me/.bundler/tmp/9630/gems/github-markdown-0.5.3 for inspection.
Results logged to /home/me/.bundler/tmp/9630/gems/github-markdown-0.5.3/ext/markdown/gem_make.out

An error occurred while installing github-markdown (0.5.3), and Bundler cannot continue.
Make sure that `gem install github-markdown -v ‘0.5.3’` succeeds before bundling.

解决方法:

sudo apt-get install ruby1.9.1-dev

原因分析:

扩展库是需要编译安装,没有dev就找不到ruby的库,所以要安装dev版本的ruby,虽然老蔡的ruby版本是ruby 1.9.3p0,但是安ruby1.9.1-dev也可以解决这个问题,大概是因为两个版本的ruby改动不大吧。

2013-09-22更新:发现在ruby 2.0下,gollum不能正确通过gem安装成功,所以还是安装ruby 1.9版本的为宜。