如何在Mac OS Yosemite上安装Nokogiri

时间:2016-11-28 01:55:40

标签: ruby-on-rails ruby rubygems nokogiri

当我尝试使用以下方式安装Nokogiri时

gem install nokogiri

我收到此错误:

ERROR:  While executing gem ... (Errno::EACCES)
Permission denied @ rb_sysopen - /usr/local/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8.1/.autotest

我先运行了这两个命令:

gem update --system
xcode-select --install

有人能看到这里有什么问题吗?

如果我使用sudo运行此操作,我会:

ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.

current directory: /usr/local/lib/ruby/gems/2.3.0/gems/nokogiri-1.6.8.1/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20161127-35515-164lnl6.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.

这是日志文件:

"clang -o conftest -I/usr/local/Cellar/ruby/2.3.3/include/ruby-2.3.0/x86_64-darwin14 -I/usr/local/Cellar/ruby/2.3.3/include/ruby-2.3.0/ruby/backward -I/usr/local/Cellar/ruby/2.3.3/include/ruby-2.3.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -fno-common -pipe  conftest.c  -L. -L/usr/local/Cellar/ruby/2.3.3/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib     -lruby.2.3.0  -lpthread -ldl -lobjc  "
Undefined symbols for architecture x86_64:
  "start", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

2 个答案:

答案 0 :(得分:0)

您可以尝试这样做:

gem install nokogiri -v '1.6.8.1' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2

答案 1 :(得分:0)

因此,结果是权限和文件所有权的混合。一旦整理完毕,我只需重新运行gem install并关闭然后重新打开终端,然后再运行rails -v