【问题标题】:Installing Nokogiri on OSX 10.10 Yosemite在 OSX 10.10 Yosemite 上安装 Nokogiri
【发布时间】:2014-07-28 07:35:40
【问题描述】:

我最近升级到 10.10 Yosemite 测试版,但在安装 Nokogiri 时遇到了问题。我正在使用 RVM 和 Ruby 1.9.3。我也遵循了here 的步骤,并尝试按照 Nokogiri 主页上的说明进行操作。

我已经通过自制软件安装了 libxml2 (2.9.1) 和 libxslt (1.1.28),并尝试使用我的 Xcode 5 安装和 Xcode 6 beta 中的命令行工具。

gem install nokogiri -v '1.5.5'
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

        /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/bin/ruby extconf.rb
checking for libxml/parser.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
    --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/grantdavis/.rvm/rubies/ruby-1.9.3-p362/bin/ruby
    --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-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-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-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-libiconv-config
    --without-libiconv-config
/Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/grantdavis/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
    from extconf.rb:114:in `<main>'

有人知道如何解决这些安装错误吗?

编辑 6/10/14: 在尝试了几天在 OSX 10.10 上安装 Nokogiri 之后,我最终放弃了任务并在我的机器上恢复了 10.9。一些库和捆绑包需要更新才能在 10.10 环境中工作。

【问题讨论】:

  • You have to install development tools first.
  • 我已经安装了开发工具。我有 Xcode 6,我已经单独下载并安装了 10.10 的命令行工具。
  • 希望这可能会有所帮助:*.com/questions/24091869/…
  • 我设法解决了升级到 ruby​​ 2.1.2(使用 rvm)的同样问题。经过一场噩梦般的宝石、啤酒和诸如此类的会议:/
  • 我有一个非常相似的问题:OS X 10.10 (Yosemite)、RVM 1.26.3、Ruby 1.9.3 (ruby-1.9.3-p551)、Nokogiri 1.6.1。我尝试了 SO 和其他地方的各种想法,但到目前为止没有运气。

标签: ruby gem bundler nokogiri homebrew


【解决方案1】:

试试这个:

按给定顺序安装这些包:

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri

尝试更新 gcc 版本:

【讨论】:

  • 我试了一下,它仍然无法安装。我相信这是安装 libv8 的问题,我在这里打开了一个问题:github.com/cowboyd/libv8/issues/123
  • @gdavis 更新 gcc 版本,然后尝试。查看更新答案中的链接。
  • 我已经尝试更新 GCC,并浏览了您在此处提到的所有帖子。以前的 OSX 版本似乎没有任何东西适用于 10.10
【解决方案2】:

我设法在 Yosemite(OS X 10.10 预览版)下安装了 Nokogiri。

第 1 步:安装 Brew

如果安装了 brew,则跳过此步骤。

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

第 2 步:安装 brew 库

brew tap homebrew/dupes
brew install libxml2 libxslt
brew install libiconv

第 3 步:下载并安装适用于 10.10 的 Apple 命令行工具

安装后需要重新启动,这一点很重要。

链接:command_line_tools_for_osx_10_10_june_2014.dmg

重启后可以在终端查看安装:

> xcode-select --install
-> xcode-select: error: command line tools are already installed, use "Software Update" to install updates

此错误表示您已正确安装命令行工具。

安装 Nokogiri

尝试在您的 Gemfile 中使用 n 个以前的 1.6.1 版本,1.6.2.1 版本当前存在“10.10 预览版”的问题。它仅适用于我的 rbenv Ruby 2.0.0p247,无法在 2.1.1 上安装。您可以尝试一下现有的 Ruby 版本。

gem install nokogiri  -v '1.6.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/

【讨论】:

  • 我卸载并重新安装了 Homebrew,因为我得到了“错误的解释器”,然后我能够运行 brew 命令。
  • brew install libiconv - 这给了我错误:权限被拒绝 - /usr/local/Cellar/libiconv/1.14
  • 还有 code-select --install 给了我这个 - 错误:权限被拒绝 - /usr/local/Cellar/libiconv/1.14 和你上面的 dmg 链接不再工作
  • 我发现在新的 Yosemite 10.10 安装中,通过 rvm 安装了 ruby​​-2.0.0-p594,我必须首先安装 symlink gcc-4.2 然后我安装了 brew 依赖项:brew install libxml2 libxslt 最后是 nokogiri gem install nokogiri -- --use-system-libraries
  • 我需要使用gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 它也适用于10.9(更改sdk版本后)。
【解决方案3】:

我认为问题与系统 Ruby 未找到或安装了多个 Ruby 有关。

  • 您是否使用 RVM 来管理红宝石?
  • ruby -v 的输出是什么?

这些应该是寻找解决方案的起点。

bad interpreter 错误与 Ruby 安装问题有关。

理想情况下,您应该从系统 Ruby 开始,即 Xcode 附带的系统。 因此,您可以使用以下命令完全卸载 Xcode:

http://osxdaily.com/2012/02/20/uninstall-xcode/

卸载brewrvm并重新安装。

【讨论】:

  • Mac OS 很早就预装了 Ruby。它不是由 Xcode 安装的,所以“从系统 Ruby 开始,Xcode 附带的那个”只是令人困惑。卸载 Xcode 不会删除系统 Ruby,只有删除系统才会这样做,而且你不想去那里。
【解决方案4】:

(完整答案在这里https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e

Homebrew 似乎在某种程度上依赖于 Ruby 在 Versions/1.8 中(尽管甚至 Mavericks 都附带了 2.0)。在 Homebrew 解决这个问题之前,我们会将系统版本的 Ruby 符号链接到 Homebrew 查找的版本。

创建文件夹:

sudo mkdir -p /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin

然后符号链接二进制文件:

sudo ln -s /usr/bin/ruby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

【讨论】:

    【解决方案5】:

    我在 MacPorts ruby​​2.1 上遇到了同样的问题:

    can not gem install nokogiri on osx10.10 with macports ruby2.1
    

    安装开始,在 100% 的单核上 CPU 达到 50%,然后 CPU 下降到接近于零,但 iostat tps 穿墙。

    这有帮助:

    # port install libiconv libxslt libxml2
    
    # gem install nokogiri -- --use-system-libraries --with-iconv-dir=/opt/local --with-xml2-dir=/opt/local --with-xslt-dir=/opt/local
    

    【讨论】:

    • 太棒了!!!唯一对我有用的是使用 macports!希望我能多点赞!
    【解决方案6】:

    Nokogiri website 的说明在 OSX 10.9 和 10.10 上都适用于我。

    brew unlink gcc-4.2      # you might not need this step
    gem uninstall nokogiri
    xcode-select --install
    gem install nokogiri
    

    【讨论】:

      【解决方案7】:

      这对我有用:

      ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.0'
      

      【讨论】:

      • 不错的一个。也为我工作。而且比所有其他建议都容易得多。
      • 我还是死在 zlib 上:Undefined symbols for architecture i386: "_gzdirect", referenced from: ___xmlParserInputBufferCreateFilename in libxml2.a(xmlIO.o) "_gzdopen", referenced from: _xmlGzfileOpenW in libxml2.a(xmlIO.o) _xmlGzfileOpen_real in libxml2.a(xmlIO.o) "_gzopen", referenced from: _xmlGzfileOpenW in libxml2.a(xmlIO.o) _xmlGzfileOpen_real in libxml2.a(xmlIO.o) ld: symbol(s) not found for architecture i386
      • 这是唯一一个对我有用而不会弄乱 macports/brew
      • 伙计,你拯救了我的一天!
      【解决方案8】:

      对我来说切换到 Xcode 5 而不是使用 Xcode 6 的 CLI 工具:

      sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
      

      【讨论】:

        【解决方案9】:

        唯一对我有用的是将编译器从 apple-gcc42 升级到 gcc48:

        brew uninstall apple-gcc42
        brew install gcc48 # this might take an hour or so
        rvm implode
        \curl -sSL https://get.rvm.io | bash -s stable # reinstall RVM
        rvm install ruby-1.9.3-p551
        bundle update libv8 # 3.16.14.3 doesn't work but 3.16.14.7 does
        bundle
        

        【讨论】:

          【解决方案10】:

          libxml2 - 优胜美地中的 1.6.6.2:

          sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries  -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include
          

          【讨论】:

          • 这对我有用,但我必须添加 -v '1.6.1' :sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -v '1.6.1' -- --use-system-libraries -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-xslt-lib=/usr/local/lib --with-xslt-include=/usr/local/include 我可以安装最新的 nokogiri gem,但运行 bundle install 除非我使用它要求的特定版本。 (也许这是一个项目配置。?对 Ruby 了解得不够多,我只知道这最终对我有用。)
          • 谢谢我也使用这些选项来安装 fastlane!
          • @DavidYeiser 你可以像这样传递 Nokogiri 版本 'nokogiri:1.6.1'
          • 我可以在没有 sudo 的情况下使用 ruby​​-2.1.0
          • @DavidYeiser 谢谢,经过多次尝试,您的解决方案是优胜美地唯一对我有用的解决方案!
          【解决方案11】:

          安装完整的 Xcode。这是旧 Nokogiri 版本唯一对我有用的东西。

          【讨论】:

            【解决方案12】:

            如果您使用的是 OS X 10.10 和 MacPorts,您还必须安装 pkgconfig:

            sudo port install pkgconfig libxml2 libxslt libiconv
            

            此外,如果您想在不添加配置选项的情况下自动使用 MacPorts 库,则需要将其添加到您的 .profile 或 .bashrc:

            export PATH=/opt/local/bin:/opt/local/sbin:$PATH
            export MANPATH=/opt/local/share/man:$MANPATH
            export LDFLAGS="-L/opt/local/lib"
            export CPPFLAGS="-I/opt/local/include"
            

            您可能还想添加这个来告诉 Nokogiri 始终使用您的系统库:

            export NOKOGIRI_USE_SYSTEM_LIBRARIES=Y
            

            添加所有这些导出后重新启动终端。

            使用此配置,您可以使用以下方式安装 Nokogiri:

            gem install nokogiri
            

            【讨论】:

            • 这个对我来说在 OS X 10.9 上运行良好。我不得不切换到sudo xcode-select -s /Library/Developer/CommandLineTools 虽然
            【解决方案13】:

            在我的情况下,错误消息写在下面,并给出了相应的解决方案。

            错误信息:

            ...
            libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.
            ...
            

            解决办法:

            gem install nokogiri -- --use-system-libraries --with-libxml2lib=/usr/local/opt/libxml2/lib/libxml2.a
            

            我直接给了libxml2.a的库路径

            【讨论】:

              【解决方案14】:

              这终于对我有用了:

              sudo gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
              

              【讨论】:

                【解决方案15】:
                sudo gem update --system
                sudo gem install nokogiri -v '1.6.6.2' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib
                

                【讨论】:

                  【解决方案16】:

                  我在 OS X Yosemite 版本 10.10.5 上收到相同的错误消息

                  我最近做了各种操作系统更新,结果发现我只需要使用以下命令接受新的 xcode 许可协议:

                  sudo xcodebuild -license
                  

                  【讨论】:

                    【解决方案17】:

                    对于 Mac OS El Capitan:

                    gem install nokogiri -v '1.6.7.1' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2

                    【讨论】:

                    • 这对我有用: sudo gem install nokogiri -v '1.6.8' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/目录/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2
                    【解决方案18】:

                    这对我有用:

                    $ brew install libxml2 libxslt  # optional?
                    $ brew install libiconv         # optional?
                    $ gem install nokogiri -v 1.6.8 -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2
                    

                    在这样的环境中:

                    $ sw_vers -productVersion 
                    10.9.4
                    $ brew -v
                    Homebrew 0.9.9 (git revision aa747; last commit 2016-05-26)
                    $ gem env
                    RubyGems Environment:
                      - RUBYGEMS VERSION: 2.0.14
                      - RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]
                    

                    【讨论】:

                      【解决方案19】:

                      解决 mac os x 上的“在 Mac OS El Capitan 上安装时无法写入 /usr/bin/nokogiri”问题:

                      sudo gem install nokogiri -n /usr/local/bin
                      

                      参考:https://www.bountysource.com/issues/28085261-can-t-write-usr-bin-nokogiri-while-installing-on-mac-os-ei-capitan

                      【讨论】:

                        【解决方案20】:

                        对于其他无法在 El Capitan 上使用它的人来说,最终对我有用的是:

                        sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-iconv-dir=/usr/local/opt/libiconv --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
                        

                        我没有安装 macports,而且我的系统是一个奇怪的大杂烩。强制为每个依赖项进行特定安装是我可以让 Nokogiri 编译的唯一方法。超级烦人,但至少它有效。

                        【讨论】:

                          【解决方案21】:

                          试试吧:

                          xcode-select --install
                          

                          【讨论】:

                            【解决方案22】:

                            这行得通:

                            gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries

                            Source

                            【讨论】: