我尝试克隆this repo并运行bundle install
。捆绑过程失败并抛出此错误:
...
Installing nokogiri 1.6.2.1 with native extensions
Building nokogiri using packaged libraries.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20151130-43880-pntnc6.rb extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
--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
extconf failed, exit code 1
Gem files will remain installed in /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.
然后我尝试运行:
gem install nokogiri -v '1.6.2.1'
现在我收到了这个错误:
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/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20151130-43942-1axq4sj.rb extconf.rb
Building nokogiri using packaged libraries.
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
--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
extconf failed, exit code 1
Gem files will remain installed in /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.2.1/gem_make.out
我尝试关注this answer但我仍然遇到上述错误。
我还尝试再次卸载并安装我的brew(based on this answer),它仍然相同。
此外,我尝试this solution但仍然收到错误。
我现在该怎么做才能确保成功安装这个nokogiri gem?
注意:我使用的是OSX 10.11.1 El Capitan。
答案 0 :(得分:111)
运行以下命令:
gem uninstall nokogiri
xcode-select --install
gem install nokogiri
来源:http://www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x
有时mac更新可能会破坏xcode CLI,因此重新安装可以解决问题: https://github.com/sparklemotion/nokogiri/issues/1445
答案 1 :(得分:25)
对我有用的(在 macOS Sierra 上)是Sam's answer和以下内容的组合:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
答案 2 :(得分:16)
使用ruby 2.3 1.6.7.2
使用代码时,bundle install
出现了类似的问题。
对我有用的是添加:
bundle config build.nokogiri --use-system-libraries
前
bundle install
答案 3 :(得分:13)
如果您正在使用捆绑包:
brew install libxml2
# If using Bundle
bundle config build.nokogiri --use-system-libraries \
--with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install
来自http://www.nokogiri.org/tutorials/installing_nokogiri.html
答案 4 :(得分:10)
我在其他答案中做了所有事情,但还得再做一件事:
答案 5 :(得分:5)
这似乎是由于nokogiri 1.6.2.1
特定问题。
我在我的Gemfile中添加了这个:
gem 'nokogiri', '~> 1.6', '>= 1.6.7'
然后运行bundle update nokogiri
,然后bundle
。现在一切都很好。
答案 6 :(得分:3)
尝试一下
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
然后安装Nokogiri
sudo gem install nokogiri
答案 7 :(得分:2)
Spencer's回答对我有用,但我还需要使用-n参数来克服记录的权限问题here.
所以最后,对我有用的命令是:
sudo gem install -n /usr/local/bin nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2 --use-system-libraries
答案 8 :(得分:0)
在rbenv gem文件夹中删除nokogiri并重新安装为我解决了这个问题。
答案 9 :(得分:0)
我有类似的问题。原因已过时xcode
。
如果您运行brew doctor
,您可能会看到它。只需打开AppStore
,即可转到updates
标签并更新您的xcode。
答案 10 :(得分:0)
在更新到xcode 10时遇到相同的问题,我通过以下步骤解决了该问题:
答案 11 :(得分:0)
如果以上方法均无效,
尝试删除Gemfile.lock
,然后重新安装gem。
答案 12 :(得分:0)
这帮助我解决了这个问题
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
答案 13 :(得分:0)
某些库的anaconda版本可能也有问题。
$ conda deactivate
$ gem uninstall nokogiri
$ gem install nokogiri
$ conda activate base
为我工作。
答案 14 :(得分:-1)
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
bundle install