今天要跑一个其他的rails项目,为了不污染原先的gemset。就重建了一个gemset, 但是bundle install的时候,安装nokogiri 1.8.4一直失败。
系统版本是Macos 10.13 High Sierra中, ruby版本是rvm安装的ruby2.3.0。

令人费解的是,同样在ruby2.3.0下的另一个gemset,nokogiri 1.8.2可以顺利安装。

网上搜了一圈后,找到了解决办法。记录如下:

设置bundle config,编译nokogiri时,使用系统xml2路径即可。

1
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2

还有一个更简单的方法,自动根据系统版本得到系统libxml2的路径

1
bundle config build.nokogiri --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2

参考资料: Installation of nokogiri fail with bundle on macOS Sierra 10.12

留言

2019-03-05