ruby - 为什么 "gem"和 "bundle"不使用相同的 libxml2?

标签 ruby gem bundler libxml2

我似乎陷入了沮丧的递归循环。我正在尝试“bundle 安装”一个项目,但结果是:

An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.6.2'` succeeds before bundling.

所以我尝试这样做:

$ gem install nokogiri -v '1.6.6.2'
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed

一切顺利!除了当我运行“bundle install”时,我再次被告知我需要先安装“gem install nokogiri -v '1.6.6.2'”。啊啊啊。

mkmf.log 文件表明这是 libxml2 的问题(出人意料)。

conftest.c:3:10: fatal error: 'libxml/xmlversion.h' file not found
#include <libxml/xmlversion.h>
         ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <libxml/xmlversion.h>
4: 
5: #if LIBXML_VERSION < 20621
6: #error libxml2 is way too old
7: #endif
/* end */

因此,搜索 libxml2(使用“sudo find/-name libxml2”)会显示这些目录,所有这些目录似乎都至少是 2.9.0 或更高版本:

  • /usr/include/libxml2
  • /usr/local/Cellar/libxml2
  • /usr/local/opt/libxml2

那么,是不是libxml2找不到的问题呢?如果是这样,我如何让 bundle install 意识到 nokogiri 已经安装,或者至少能够像“gem install”一样安装它?虽然我想为此找到解决方案,但我真的很想了解“幕后”发生的事情,以便将来进行故障排除。

最佳答案

在我的 Mac OS X 上,我运行了这些命令,问题就解决了。

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

关于ruby - 为什么 "gem"和 "bundle"不使用相同的 libxml2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32466606/

相关文章:

ruby-on-rails - Bootstrap 的 ruby gem 有什么区别?

ruby - 添加总和等于最大元素的数组元素

ruby - gem 安装错误 : 'Please specify at least one gem name'

ruby - 'bundle exec' 提示 gem 没有被安装,即使在 'bundle install' 之后

ruby-on-rails - 找不到 'bundler'

ruby - :/mean in Ruby? 是什么意思

ruby-on-rails - 使用 Shoulda Ruby on Rails 获取 HTTP 响应

ruby-on-rails - bundle show gemname 和 gem list gemname 的区别

ruby - 使用预发布 gem 来满足与 Bundler 的传递依赖

ruby - bundler 、rubygems 和动态使用 gems