rails无法安装nokogiri w Mavericks& rbenv

时间:2014-07-21 00:03:44

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

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

即使下载并安装了10月版的XCode命令行工具并运行后,我仍然坚持使用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

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

3 个答案:

答案 0 :(得分:3)

几个星期前我收到了同样的错误。这就是我解决它的方法:

您必须手动安装损坏的库。使用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

答案 1 :(得分:2)

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

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

答案 2 :(得分:0)

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

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

最后是为我工作的命令

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