由于缺少原生扩展,Nokogiri安装错误

时间:2015-09-10 03:04:10

标签: ruby-on-rails ruby nokogiri ubuntu-14.04

我一直在尝试基于these instructions安装Ruby on Rails。但是,运行rootTarget时出现以下错误:

gem install rails -v 4.2.4

我尝试通过运行Fetching: rack-1.6.4.gem (100%) Successfully installed rack-1.6.4 Building native extensions. This could take a while... ERROR: Error installing rails: ERROR: Failed to build gem native extension. /home/falak/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150909-22683-172bl7d.rb extconf.rb checking if the C compiler accepts ... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/home/falak/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME) --help --clean /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile' from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror' from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile' from extconf.rb:80:in `nokogiri_try_compile' from extconf.rb:87:in `block in add_cflags' from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags' from extconf.rb:86:in `add_cflags' from extconf.rb:337:in `<main>' extconf failed, exit code 1 Gem files will remain installed in /home/falak/.rvm/gems/ruby-2.2.3/gems/nokogiri-1.6.6.2 for inspection. Results logged to /home/falak/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/nokogiri-1.6.6.2/gem_make.out 使用系统库安装nokogiri,但是我收到以下错误:

gem install nokogiri -v 1.6.2.1 -- --use-system-libraries

6 个答案:

答案 0 :(得分:19)

尝试安装libgmp-dev

apt-get install libgmp-dev

答案 1 :(得分:6)

使用RVM在ruby 2.2.3中安装rails也是其他用户的主要问题。现在,你仍然可以在ruby 2.2.2中获得rails 4.2.4。 尝试:

    rvm install 2.2.2
    rvm --default use 2.2.2
    gem install rails

这应该仍然有用。 RVM由于某种原因没有在2.2.3中安装正确的标题,以便您构建宝石。

答案 2 :(得分:2)

对于 OS X 用户:记得更新Xcode命令行开发人员工具,这是99%OS X用户的问题。 xcode-select --install

答案 3 :(得分:2)

你可以尝试这个神奇的解决方案

解决方案是:

sudo apt-get install ruby-dev

或者,如果这不起作用,根据您的ruby版本,运行类似:

sudo apt-get install ruby1.9.1-dev

应该解决你的问题。

仍然无法使用?安装ruby-dev后,请尝试以下操作:

sudo apt-get install make

答案 4 :(得分:2)

此解决方案适用于nokogiri错误:

sudo apt-get install ruby-dev

答案 5 :(得分:0)

如错误所示,请检查mkmf.log文件。在那里你会找到丢失的头文件。

在我的情况下,我错过了zlib.h.错误是:

  

找不到#include文件“zlib.h”

所以要解决它:

sudo apt-get install zlib1g-dev

要查找所需的开发包,可以使用apt-file

$ apt-file search zlib.h
zlib1g-dev: /usr/include/zlib.h