sudo:port:找不到命令; mac os x

时间:2014-08-27 01:34:36

标签: ruby-on-rails ruby macos

我正在尝试使用Ruby和Ruby on Rails构建一个todo列表。在我的rails应用程序中,我添加了我需要的宝石,然后键入' bundle'在我的终端。一切正常,直到:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    /Users/Misha/.rbenv/versions/2.1.2/bin/ruby extconf.rb 
Building nokogiri using packaged libraries.
-----
libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----

我转到提供的链接,对于mac,它指示执行以下命令:

sudo port install libxml2 libxslt

sudo gem install nokogiri

然后我得到了找不到的命令。我尝试了类似的问题和解决方案:

sudo vi /etc/paths

Add 2 following lines:

/opt/local/bin

/opt/local/sbin

但仍有同样的问题。

2 个答案:

答案 0 :(得分:2)

我怀疑sudo port install libxml2 libxslt失败了,因为您没有安装MacPorts软件包管理器。但是,我会安装Homebrew(这是我个人的包管理器首选项):

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

然后继续使用instructions provided in the error message,将brew替换为sudo port

brew install libxml2 libxslt

如果有效,请尝试:

sudo gem install nokogiri

答案 1 :(得分:0)

除了@thohl的回答,我完全同意。 Nokogiri有时很难安装。出于这个原因,我保留了以下食谱:

cd $( brew --prefix )
git checkout 763d946 Library/Formula/libxml2.rb
brew unlink libxml2
brew install libxml2 libxslt
git checkout master Library/Formula/libxml2.rb

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri --verbose -- --with-xslt-dir=$( brew --prefix )/Cellar/libxslt/1.1.28 --with-iconv dir=$( brew --prefix )/Cellar/libiconv/1.14 --with-xml2-include=$( brew --prefix )/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=$( brew --prefix )/homebrew/Cellar/libxml2/2.8.0/lib --use-system-libraries

这些咒语在我的案例中成了伎俩