权限被拒绝@ rb_sysopen宝石安装错误/ LoadError Nokogiri

时间:2019-03-29 22:09:07

标签: ruby rubygems nokogiri

试图用require 'nokogiri'运行一个简单的ruby脚本确实很费劲。

我收到此错误:

Traceback (most recent call last):
    3: from courses2.rb:1:in `<main>'
    2: from /Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require'
    1: from /Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
/Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require': cannot load such file -- nokogiri (LoadError)

它肯定已经安装了,但是即使我继续输入gem install nokogiri

我收到此错误:

ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.10.2/bin/nokogiri

我了解这是一个权限问题,因此正在尝试参考此question以获得答案。它没有帮助。

也没有该链接上的信息:https://medium.com/@iranr/how-to-fix-ruby-gem-installing-error-on-macos-be7d4dbfc916


编辑:先完成gem uninstall nokogirigem install nokogiri之后,现在出现以下错误:

Building native extensions. This could take a while...
ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/Users/marko/.rbenv/versions/2.5.1/bin/ruby -I /Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0 -r ./siteconf20190329-16424-1ynq7n7.rb extconf.rb
checking if the C compiler accepts  -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
*** 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.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/marko/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
/Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `require': cannot load such file -- mini_portile2 (LoadError)
    from /Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
    from /Users/marko/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:34:in `require'
    from extconf.rb:470:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/nokogiri-1.10.2/mkmf.log

Permission denied @ rb_file_s_rename - (mkmf.log, /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/nokogiri-1.10.2/mkmf.log)

Gem files will remain installed in /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nokogiri-1.10.2 for inspection.
Results logged to /Users/marko/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/nokogiri-1.10.2/gem_make.out

mkmf.log我得到

"clang -o conftest -I/Users/marko/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-darwin17 -I/Users/marko/.rbenv/versions/2.5.1/include/ruby-2.5.0/ruby/backward -I/Users/marko/.rbenv/versions/2.5.1/include/ruby-2.5.0 -I. -I/Users/marko/.rbenv/versions/2.5.1/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -Wno-error=shorten-64-to-32  -pipe  -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2 conftest.c  -L. -L/Users/marko/.rbenv/versions/2.5.1/lib -L. -L/Users/marko/.rbenv/versions/2.5.1/lib  -fstack-protector -L/usr/local/lib    -lexslt -lxslt -lxml2  -lruby.2.5.1-static -framework Foundation -lexslt -lxslt -lxml2  -lpthread -lgmp -ldl -lobjc  "
ld: warning: text-based stub file /System/Library/Frameworks//Foundation.framework/Foundation.tbd and library file /System/Library/Frameworks//Foundation.framework/Foundation are out of sync. Falling back to library file for linking.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10: 
11:   return 0;
12: }
13: extern void xmlSchemaSetParserStructuredErrors();
14: int t(void) { xmlSchemaSetParserStructuredErrors(); return 0; }
/* end */

--------------------

2 个答案:

答案 0 :(得分:0)

不太确定问题的原因是什么,但是切换到RVM可以解决此问题。

在您的终端中执行以下操作:

  1. brew remove rbenv
  2. rm -rf ~/.rbenv
  3. \curl -sSL https://get.rvm.io | bash
  4. rvm install 2.5.1(或正确的版本号)
  5. rvm use 2.5.1(或正确的版本号

答案 1 :(得分:0)

您需要更改GEM_HOME或进行类似sudo gem install bundler -n /usr/local/bin的操作。

    export PATH=$PATH':/path/to/add'
    export GEM_HOME=$HOME/.gem
    export GEM_PATH=$HOME/.gem

但这仅对当前会话有效。要使它们更永久,请将这些行添加到您的~/.bashrc中。