gem文件安装正常但无法使用bundle install进行编译

时间:2016-02-18 21:22:33

标签: ruby-on-rails ruby bundler

我刚开始学习Rails并且正在努力摆脱障碍......

$ rails new sample_app
$ cd sample_app
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Using rake 10.5.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types 2.99
Using arel 6.0.3
Using debug_inspector 0.0.2
Using byebug 8.2.2
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using concurrent-ruby 1.0.0
Using multi_json 1.11.2
Using bundler 1.11.2
Using sass 3.4.21
Using tilt 2.0.2
Using spring 1.6.3
Using sqlite3 1.3.11
Using rdoc 4.2.2
Using tzinfo 1.2.2
Installing nokogiri 1.6.7.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.7.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160218-90999-1e1suiq.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
-----
libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.
-----
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --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
    --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-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config
    --with-xml2lib
    --without-xml2lib
    --with-libxml2lib
    --without-libxml2lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/gem_make.out
Using rack-test 0.6.3
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using sprockets 3.5.2
Using sdoc 0.4.1
Using activesupport 4.2.5.1
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

然后我终于安装了nokogiri ...

$ gem install nokogiri -- --use-system-libraries
Building native extensions with: '--use-system-libraries'
This could take a while...
Successfully installed nokogiri-1.6.7.2
Parsing documentation for nokogiri-1.6.7.2
Done installing documentation for nokogiri after 1 seconds
1 gem installed

然后我重做bundle install,我得到了之前的错误。

如果我这样做:

$ bundle config build.nokogiri --use-system-libraries & bundle install

我得到同样的错误。

以下是一些规格:

$ rails --version
Rails 4.2.5.1
$ ruby --version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.11.1
BuildVersion:   15B42

关于我在这里做错了什么想法?

2 个答案:

答案 0 :(得分:1)

我会尝试提供一些背景信息(因为你刚刚开始,这可能有助于骑行)。

在Ruby和Rails中,你将安装很多gems(“库”)。 有时库需要/想要快速,因此gem的一部分用C编写。安装这些部件可能很困难,那就是

Installing nokogiri 1.6.7.2 with native extensions

这些原生扩展程序need to be compiled and dynamically linked and have gained a reputation for being complicated to install所以这可能比你想要的更频繁:(。

在Nokogiris的案例中,你很幸运,因为他们有whole page dedicated to fixing installation issues here.

为了了解您的情况,常规gem install有效,我猜您需要告诉bundler使用系统库

export NOKOGIRI_USE_SYSTEM_LIBRARIES=1
bundle install

修改

我错过了你已经指明了这一点,也许可以试试:

--with-xml2-include=/wherever/brew/install/it

并查看here

答案 1 :(得分:0)

您的操作系统缺少libxml2等库。 所以试试:

brew install libxml2
brew install libxslt