Ruby-on-rails 安装 nokogiri 时出错:无法构建 gem 本机扩展并且缺少 libiconv (OSX)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33996523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error installing nokogiri: Failed to build gem native extension & libiconv is missing (OSX)
提问by Zulhilmi Zainudin
I try to clone this repoand run bundle install. The bundle process failed and throw this error:
我尝试克隆这个 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.
Then I try to run this:
然后我尝试运行这个:
gem install nokogiri -v '1.6.2.1'
And now I get this error:
现在我收到这个错误:
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
I tried to follow this answerbut I still get the same error above.
我试图遵循这个答案,但我仍然遇到上述相同的错误。
I also try to uninstall and install my brew again (based on this answer) and it's still same.
我还尝试再次卸载并安装我的 brew(基于此答案),但它仍然相同。
Also, I try this solutionbut still get the error.
另外,我尝试了这个解决方案,但仍然出现错误。
What should I do now to make sure this nokogiri gem installed successfully?
我现在应该怎么做才能确保这个 nokogiri gem 安装成功?
Note: I'm using OSX 10.11.1 El Capitan.
注意:我使用的是 OSX 10.11.1 El Capitan。
回答by pthamm
Run these commands:
运行这些命令:
gem uninstall nokogiri
xcode-select --install
gem install nokogiri
source: http://www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x
来源:http: //www.nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x
sometimes mac updates can break xcode CLI so reinstalling can fix the issue: https://github.com/sparklemotion/nokogiri/issues/1445
有时 mac 更新会破坏 xcode CLI,因此重新安装可以解决问题:https: //github.com/sparklemotion/nokogiri/issues/1445
回答by spencer.sm
What worked for me (on macOS Sierra) was a combination of Sam's answerand the following:
对我有用的(在macOS Sierra 上)是Sam 的回答和以下内容的组合:
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
回答by Andy Ray
If you're using bundle:
如果您使用捆绑包:
brew install libxml2
# If using Bundle
bundle config build.nokogiri --use-system-libraries \
--with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install
from http://www.nokogiri.org/tutorials/installing_nokogiri.html
来自http://www.nokogiri.org/tutorials/installing_nokogiri.html
回答by Jay
I had a similar issue with 1.6.7.2when bundle installing on codeship with ruby 2.3.
我在使用 ruby 2.3 进行 codeship1.6.7.2时遇到了类似的问题bundle install。
What worked for me was adding:
对我有用的是添加:
bundle config build.nokogiri --use-system-libraries
bundle config build.nokogiri --use-system-libraries
before
前
bundle install
bundle install
回答by Sam Selikoff
I did everything in the other answers, but had to do one more thing:
我在其他答案中做了所有事情,但不得不再做一件事:
- Open Xcode
- Click "Agree"
- Wait a bit, close Xcode
- Rejoice
- 打开 Xcode
- 点击“同意”
- 稍等,关闭Xcode
- 麾
回答by Zulhilmi Zainudin
Seems like this is due to nokogiri 1.6.2.1specific problem.
似乎这是由于 nokogiri1.6.2.1特定问题。
I add this inside my Gemfile:
我将它添加到我的 Gemfile 中:
gem 'nokogiri', '~> 1.6', '>= 1.6.7'
And run bundle update nokogiriand then bundle. Everything now working fine.
然后运行bundle update nokogiri然后bundle。现在一切正常。
回答by Lalana Chamika
Try this
尝试这个
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
And then install Nokogiri
然后安装Nokogiri
sudo gem install nokogiri
回答by Naupaka Zimmerman
It may also be an issue with the anaconda version of some of the libs.
这也可能是某些库的 anaconda 版本的问题。
$ conda deactivate
$ gem uninstall nokogiri
$ gem install nokogiri
$ conda activate base
worked for me.
对我来说有效。
回答by Drew Jex
Spencer'sanswer worked for me, but I also needed to use the -n parameter to overcome the permission issue documented here.
Spencer 的回答对我有用,但我还需要使用 -n 参数来克服此处记录的权限问题。
So in the end, the command that worked for me was:
所以最后,对我有用的命令是:
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
回答by Aks
I had same issue while updating to xcode 10, I resolved it with following steps :
我在更新到 xcode 10 时遇到了同样的问题,我通过以下步骤解决了它:
- xcode-select --install
- bundle install --deployment
- gem install nokogiri
- xcode-select --install
- 捆绑安装 --deployment
- 宝石安装 nokogiri

