Ruby-on-rails 无法构建 gem 本机扩展 — Rails 安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12552929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:47:54  来源:igfitidea点击:

Failed to build gem native extension — Rails install

ruby-on-railsrubyrubygems

提问by pata kusik

I have been installing Ruby on Rails based on the instruction from edX online class.

我一直在根据 edX 在线课程的说明安装 Ruby on Rails。

Here is a list of terminal commands, and, where relevant, corresponding output:

以下是终端命令列表,以及相关的相应输出:

$ sudo apt-get install ruby1.9.1

installation successful

安装成功

$ 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

Up to here, everything looked fine, but the I tried to install rails and failed:

到这里为止,一切看起来都很好,但是我尝试安装 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

回答by Suhail Patel

mkmfis part of the ruby1.9.1-devpackage. This package contains the header files needed for extension libraries for Ruby 1.9.1. You need to install the ruby1.9.1-devpackage by doing:

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

sudo apt-get install ruby1.9.1-dev

Then you can install Rails as per normal.

然后你可以正常安装Rails。

Generally it's easier to just do:

一般来说,这样做更容易:

sudo apt-get install ruby-dev

回答by user1821237

The suggested answer only works for certain versions of ruby. Some commenters suggest using ruby-dev; that didn't work for me either.

建议的答案仅适用于某些版本的 ruby​​。一些评论者建议使用 ruby​​-dev;这对我也不起作用。

sudo apt-get install ruby-all-dev

worked for me.

对我来说有效。

回答by Tanzeel

sudo apt-get install ruby-dev

worked for me

对我来说有效