4

尝试安装 nokogiri 时,我得到:

± gem install nokogiri -v '1.6.0'
Building native extensions.  This could take a while...
/Users/Chintan/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

        /Users/Chintan/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
/Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:199: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin11.4.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-apple-darwin11.4.0/ports/libxml2/2.8.0/configure.log' to see what happened.
*** 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/Chintan/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
/Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:235:in `block in execute': Failed to complete configure task (RuntimeError)
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:227:in `chdir'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:227:in `execute'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:57:in `configure'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/mini_portile-0.5.0/lib/mini_portile.rb:100:in `cook'
    from extconf.rb:101:in `block in <main>'
    from extconf.rb:119:in `call'
    from extconf.rb:119:in `block in <main>'
    from extconf.rb:109:in `tap'
    from extconf.rb:109:in `<main>'


Gem files will remain installed in /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/nokogiri-1.6.0 for inspection.
Results logged to /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out

看起来问题出在 C 编译器上,这是 configure.log 的内容:

checking build system type... x86_64-apple-darwin12.2.1
checking host system type... x86_64-apple-darwin12.2.1
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/nokogiri-1.6.0/ext/nokogiri/tmp/x86_64-apple-darwin11.4.0/ports/libxml2/2.8.0/libxml2-2.8.0':
configure: error: C compiler cannot create executables
See `config.log' for more details

更新:重新安装我的编译器可以让我安装 nokogiri,但我无法启动 rails 服务器:

/Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require': dlopen(/Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rmagick-2.13.2/lib/RMagick2.bundle, 9): Library not loaded: /usr/local/lib/libMagickCore-Q16.7.dylib (LoadError)
  Referenced from: /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rmagick-2.13.2/lib/RMagick2.bundle
  Reason: image not found - /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rmagick-2.13.2/lib/RMagick2.bundle
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rmagick-2.13.2/lib/RMagick.rb:11:in `<top (required)>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/Chintan/Documents/Work/Aidin/config/initializers/imagemagick.rb:1:in `<top (required)>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:43:in `load'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/engine.rb:587:in `each'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/engine.rb:587:in `block in <class:Engine>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Chintan/Documents/Work/Aidin/config/environment.rb:5:in `<top (required)>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
    from /Users/Chintan/Documents/Work/Aidin/config.ru:3:in `block in <main>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /Users/Chintan/Documents/Work/Aidin/config.ru:in `new'
    from /Users/Chintan/Documents/Work/Aidin/config.ru:in `<main>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
    from /Users/Chintan/.rvm/gems/ruby-1.9.3-p327@aidin_development/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

上次我遇到这个问题时,解决方法是重新安装 apple-gcc42,但这似乎不是现在的问题。有任何想法吗?

4

6 回答 6

3

看起来这个问题已经解决了:nokogiri will not install - ERROR: Failed to build gem native extension

尝试

sudo apt-get install libxslt-dev libxml2-dev
于 2013-07-12T07:07:06.870 回答
2

这种解决方法对我有用:https ://github.com/opscode-cookbooks/xml/issues/19

1) 添加 liblzma-dev 和 z-lib1g-dev

sudo apt-get install liblzma-dev zlib1g-dev

2)使用那些安装

sudo /opt/chef/embedded/bin/gem install nokogiri -q --no-rdoc --no-ri -v "1.6.5" -- --use-system-libraries --with-xml2-include=/usr/include/libxml2
于 2015-04-20T18:35:38.003 回答
2

您需要 libxslt 和 libxml2 来构建 nokogiri。由于您使用的是 MacOS X,因此您需要通过 MacPorts 或 Homebrew 进行安装。对于自制软件,请尝试:

brew install libxslt libxml2
于 2013-07-23T04:33:53.450 回答
2

自制 0.9

显然有些人在将 libiconv 安装在 homebrew 0.9 下时遇到了问题(参见问题 #442)。据报道,这是有效的:

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

然后(最后)安装 nokogiri:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 \
                        --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib \ 
                        --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 \ 
                        --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include \ 
                        --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
于 2014-07-01T11:49:11.377 回答
0

这对我有用http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/

这是一个涉及开发人员工具的 Mavericks 问题。

于 2014-07-01T11:37:41.283 回答
0

nokogiri网站上详细介绍了更全面的案例

对我来说,在 MacOs 上,它就像这里所建议的那样工作:

brew install libxml2
# If installing directly
gem install nokogiri -- --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
# If using Bundle
bundle config build.nokogiri --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install

使用它时,一定要使用它,$(brew --prefix libxml2) 因为它会为您的 Homebrew 安装使用正确的位置。

于 2019-03-26T14:17:33.597 回答