【问题标题】:rails cannot install nokogiri w Mavericks & rbenvrails 无法安装 nokogiri w Mavericks & rbenv
【发布时间】:2014-09-11 10:14:57
【问题描述】:

运行 OSX 10.9.4 和 XCode 5.1.1,我最近从 rvm 切换到 Rbenv,所以我需要重新安装一些 gem,没什么大不了的,但是...

即使在下载并安装 XCode 命令行工具的 10 月版并运行之后,我仍然无法安装 Nokogiri gem:

sudo xcode-select -s /Library/Developer/CommandLineTools/

我还安装了 libxml2 libxslt w brew

我还是报错,有什么办法可以解决这个问题吗?

    yves$ gem install nokogiri
    Building native extensions.  This could take a while...
    Building nokogiri using packaged libraries.
    ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

        /Users/yves/.rbenv/versions/2.1.2/bin/ruby extconf.rb
    Building nokogiri using packaged libraries.
    checking for iconv.h... *** 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=/Users/yves/.rbenv/versions/2.1.2/bin/ruby
        --help
        --clean
        --use-system-libraries
        --enable-static
        --disable-static
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --enable-cross-build
        --disable-cross-build
    /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:1067:in `block in have_header'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:321:in `open'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
        from /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:1066:in `have_header'
        from extconf.rb:103:in `have_iconv?'
        from extconf.rb:148:in `block (2 levels) in iconv_prefix'
        from extconf.rb:90:in `preserving_globals'
        from extconf.rb:143:in `block in iconv_prefix'
        from extconf.rb:120:in `each_iconv_idir'
        from extconf.rb:137:in `iconv_prefix'
        from extconf.rb:427:in `block in <main>'
        from extconf.rb:161:in `block in process_recipe'
        from extconf.rb:154:in `tap'
        from extconf.rb:154:in `process_recipe'
        from extconf.rb:422:in `<main>'

    extconf failed, exit code 1

    Gem files will remain installed in /Users/yves/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.3 for inspection.
    Results logged to /Users/yves/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.3/gem_make.out

安装 libxml2 libxslt 时出现警告,可能会干扰 nokogiri 安装?

             yves$ brew install libxml2 libxslt
        ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libxml2-2.9
        ######################################################################## 100.0%
        ==> Pouring libxml2-2.9.1.mavericks.bottle.1.tar.gz
        ==> Caveats
        This formula is keg-only, so it was not symlinked into /usr/local.

        Mac OS X already provides this software and installing another version in
        parallel can cause all kinds of trouble.

        Generally there are no consequences of this for you. If you build your
        own software and it requires this formula, you'll need to add to your
        build variables:

            LDFLAGS:  -L/usr/local/opt/libxml2/lib
            CPPFLAGS: -I/usr/local/opt/libxml2/include

接下来我该怎么做?谢谢你的建议

【问题讨论】:

    标签: ruby-on-rails xcode nokogiri osx-mavericks


    【解决方案1】:

    几周前我遇到了同样的错误。我就是这样解决的:

    您必须手动安装损坏的库。使用Homebrew,它是 OS X 的包管理器。确保先更新brew update,然后安装库:

    brew install libxml2 libxslt
    brew link libxml2 libxslt
    

    您可能需要从源安装libiconv

    wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
    tar xvfz libiconv-1.13.1.tar.gz
    cd libiconv-1.13.1
    ./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
    make
    sudo make install
    

    然后你应该能够安装 gem。

    从这里的文档中引用: http://nokogiri.org/tutorials/installing_nokogiri.html#homebrew_09

    您可能还需要在安装库后运行rbenv rehash

    【讨论】:

    • 非常感谢...我昨天错过了 brew 链接!!!正如你所说,我访问了 nokogiri 网站...... ;-)) 我不知道我是否真的需要添加选项 --with-xml2-include --with-xml2-lib 等等......我'将尝试不使用选项,如果使用选项失败....
    • 太糟糕了,我收到错误 /Users/yves/.rbenv/versions/2.1.2/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed生成可执行文件。 (RuntimeError) 你必须先安装开发工具。但是它已经安装了
    • 这是有效的:sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose - -no-ri --no-rdoc
    • 太糟糕了,适用于 nokogiri 1.6.1,不适用于 1.6.3 升级!!!!我现在很生气......
    【解决方案2】:

    几天前我遇到了同样的问题,这个帖子帮助了我

    https://github.com/sparklemotion/nokogiri/issues/1111

    终于找到了对我有用的命令

    gem install nokogiri -- --with-xslt-dir=/usr/local/opt/libxslt
    

    【讨论】:

      【解决方案3】:

      我在其中一个论坛上找到了解决方案:

      https://github.com/sparklemotion/nokogiri/issues/1111

      经过将近一周的搜索,终于成功了:

      sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -- --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
      

      GL

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-17
        • 2014-03-20
        • 2017-01-29
        • 2014-05-09
        • 1970-01-01
        • 2015-02-14
        • 2016-02-03
        • 1970-01-01
        相关资源
        最近更新 更多