试图安装Rails,无法构建Gem Native Extension

时间:2012-11-28 23:24:19

标签: ruby-on-rails

我正在尝试使用Ruby Version Manager在Ubuntu 12.10上安装Rails。我相信Ruby和RubyGems安装正确,这些是我的版本:

ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
gem -v: 1.8.23

我正在尝试使用

安装rails
sudo gem install rails -v 3.2.9

这会获取大量宝石,但在构建原生扩展时遇到问题:

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/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:in `require'
    from extconf.rb:1:in `<main>'

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

知道我做错了什么吗?如果有帮助,我正在尝试按照http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-install_rails上的教程。

谢谢!

2 个答案:

答案 0 :(得分:1)

您是否安装了C编译器?如果没有,您应该运行sudo apt-get install build-essential来设置编译器工具链

答案 1 :(得分:1)

以普通用户身份安装gem,而不是sudo:

  

gem install rails

或者安装ruby dev包。 SO中有很多类似的答案:

Failed to build gem native extension — Rails install

Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)