无法构建本地扩展宝石- Rails安装失败

74

我一直按照edX在线课程的指导安装Ruby on Rails。

这是一系列终端命令及相关输出列表:

$ sudo apt-get install ruby1.9.1

安装成功

$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz
$ tar zxvf ruby-1.8.24.tgz
$ cd ruby-1..8.24
$ sudo ruby setup.rb
RubyGems 1.8.24 installed

== 1.8.24 / 2012-04-27

* 1 bug fix:

  * Install the .pem files properly. Fixes #320
  * Remove OpenSSL dependency from the http code path


------------------------------------------------------------------------------

RubyGems installed the following executables:
    /usr/bin/gem1.9.1

到这里为止,一切看起来都很好,但是我尝试安装Rails却失败了:

$ sudo gem install rails
Fetching: i18n-0.6.1.gem (100%)
Fetching: multi_json-1.3.6.gem (100%)
Fetching: activesupport-3.2.8.gem (100%)
Fetching: builder-3.0.3.gem (100%)
Fetching: activemodel-3.2.8.gem (100%)
Fetching: rack-1.4.1.gem (100%)
Fetching: rack-cache-1.2.gem (100%)
Fetching: rack-test-0.6.1.gem (100%)
Fetching: journey-1.0.4.gem (100%)
Fetching: hike-1.2.1.gem (100%)
Fetching: tilt-1.3.3.gem (100%)
Fetching: sprockets-2.1.3.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.2.8.gem (100%)
Fetching: arel-3.0.2.gem (100%)
Fetching: tzinfo-0.3.33.gem (100%)
Fetching: activerecord-3.2.8.gem (100%)
Fetching: activeresource-3.2.8.gem (100%)
Fetching: mime-types-1.19.gem (100%)
Fetching: polyglot-0.3.3.gem (100%)
Fetching: treetop-1.4.10.gem (100%)
Fetching: mail-2.4.4.gem (100%)
Fetching: actionmailer-3.2.8.gem (100%)
Fetching: rake-0.9.2.2.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: thor-0.16.0.gem (100%)
Fetching: json-1.7.5.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
    from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from extconf.rb:1:in `<main>'


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/json-1.7.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/json-1.7.5/ext/json/ext/generator/gem_make.out

3个回答

161

mkmfruby1.9.1-dev包的一部分。该包含了扩展Ruby 1.9.1的头文件所需的文件。您需要执行以下操作安装ruby1.9.1-dev包:

sudo apt-get install ruby1.9.1-dev

然后您可以像平常安装Rails一样进行安装。

通常来说,更容易的方式是直接执行:

sudo apt-get install ruby-dev

不得不写 sudo apt-get install ruby1.9.1-dev 而不是 sudo apt-get install ruby1.9-dev。除此之外一切正常,谢谢。 - pata kusik
非常感谢你!我在使用sass -watch时遇到了rb-inotify依赖问题,让我有些疯狂。 - jossemarGT
17
记录一下,对我来说 sudo apt-get install ruby-dev 就足够了。 - ezakto
再次感谢。我正在尝试在Ubuntu上按照这些说明设置gh-pages gem:https://help.github.com/articles/using-jekyll-with-pages/,但我可能错过了安装ruby-dev步骤。 - davewasthere
大家好,我遇到了这个错误。 sudo: apt-get: command not found 我能用brew安装ruby-dev吗? - GOrozco58
显示剩余2条评论

8
建议的答案仅适用于某些版本的Ruby。一些评论者建议使用ruby-dev;但这对我也没用。
sudo apt-get install ruby-all-dev

对我有用。


5
sudo apt-get install ruby-dev

对我有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接