无法构建gem本机扩展-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

到这里为止,一切看起来都不错,但是我尝试安装滑轨并失败了:

$ 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

Answers:


162

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 2012年

非常感谢老兄!我对rb-inotify依赖问题感到发疯...(使用sass -watch)
jossemarGT 2013年

17
记录下来,sudo apt-get install ruby-dev对我来说足够了。
ezakto 2014年

再次感谢。我试图按照以下说明在ubuntu上设置gh-pages gem:help.github.com/articles/using-jekyll-with-pages,但是我一定错过了ruby-dev安装步骤。
davewasthere 2014年

是的。在我的计算机上,该版本是ruby.v.2.1,如果我安装了ruby1.9.1-dev,结果仍然有错误。如果我使用sudo apt-get install ruby-dev,ubuntu会安装ruby2.1-dev,所以结果还可以!
bnPYSse 2014年

8

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

sudo apt-get install ruby-all-dev

为我工作。


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.