【问题标题】:Nokogiri error on installation due to missing native extension由于缺少本机扩展,安装时出现 Nokogiri 错误
【发布时间】:2015-09-10 03:04:10
【问题描述】:

我一直在尝试基于these instructions 安装 Ruby on Rails。但是,运行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

我尝试通过运行gem install nokogiri -v 1.6.2.1 -- --use-system-libraries 使用系统库安装 nokogiri,但出现以下错误:

Building native extensions with: '--use-system-libraries'
This could take a while...
Building nokogiri using system libraries.
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    /home/falak/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150909-23169-twqmu6.rb extconf.rb --use-system-libraries
Building nokogiri using system libraries.
*** 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
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
/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:541:in `try_link0'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:637:in `try_ldflags'
    from /home/falak/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/mkmf.rb:1780:in `pkg_config'
    from extconf.rb:338: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.2.1 for inspection.
Results logged to /home/falak/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/nokogiri-1.6.2.1/gem_make.out

【问题讨论】:

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


    【解决方案1】:

    尝试安装libgmp-dev

    apt-get install libgmp-dev
    

    【讨论】:

      【解决方案2】:

      在 ruby​​ 2.2.3 中使用 RVM 安装 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 中安装正确的头文件供您构建 gem。

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 这实际上是我在 2017 年解决方案的一部分。但我现在得到了这个错误 While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
        • @rattanak,尝试在命令前面添加“sudo”。然后它会询问你的密码
        • 我试过了。 sudo gem install bundler ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
        • 试试 sudo gem install nokogiri -n /usr/local/bin
        【解决方案4】:

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

        解决办法是:

        sudo apt-get install ruby-dev
        

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

        sudo apt-get install ruby1.9.1-dev
        

        应该可以解决您的问题。

        还是不行?安装 ruby​​-dev 后尝试以下操作:

        sudo apt-get install make
        

        【讨论】:

          【解决方案5】:

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

          sudo apt-get install ruby-dev
          

          【讨论】:

            【解决方案6】:

            正如错误所说,检查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
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2014-09-24
              • 2016-06-25
              • 1970-01-01
              • 1970-01-01
              • 2018-04-14
              • 2016-02-14
              • 1970-01-01
              相关资源
              最近更新 更多