在 OSX Mavericks 上的 Rails 上安装 Ruby 时出现 libxml2 问题

Problems with libxml2 when installing Ruby on Rails on OSX Mavericks

我在终端的 Rails 上安装 Ruby 时遇到问题。

有没有其他人在终端遇到以下错误:

checking for main() in -llzma... yes
checking for xmlParseDoc() in libxml/parser.h... no
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
-----
libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.
-----
*** 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.

我使用的是标准 bash:

$ gem install rails

我该如何解决这个问题?我在这里尝试了一些关于堆栈交换的东西,但到目前为止没有任何效果......

在终端中使用 $ brew list 会产生:

Michaels-iMac:~ iMacHome$ brew list
autoconf    libksba     libxslt     pkg-config
automake    libtool     libyaml     readline
libgpg-error    libxml2     openssl
Michaels-iMac:~ iMacHome$

好像有...

问题可能出在您的 RVM 上。

试试这个命令:

 rvm cleanup all
 rvm pkg uninstall libxml2
 rvm reinstall all --force

或upgrade/reinstall到最新的 RVM 安装。

-- 要为 Ruby 版本全局正确安装 rails gem:

rvm use <rubyversion>
gem install rails

在 ruby 2.1.5 上使用 rails 的示例:

rvm use 2.1.5
gem install rails

假设您已经 Xcode 安装试试这个

gem install rails -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.‌platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries