0

Really struggling trying to run a simple ruby script with require 'nokogiri'.

I get this error:

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)

It is definitely installed, but even when I go ahead and type gem install nokogiri

I get this error:

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

I understand it is a Permissions problem and was trying to reference this question for answers. It didn't help.

Nor does the information on this link: https://medium.com/@iranr/how-to-fix-ruby-gem-installing-error-on-macos-be7d4dbfc916


EDIT: After doing gem uninstall nokogiri and then gem install nokogiri, I now get the following error:

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

From the mkmf.log I get

"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 */

--------------------
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
degenPenguin
  • 725
  • 1
  • 8
  • 23
  • 1
    "_I have tried so many different things!_" But you haven't tried telling us in your post what you've done or what the outcomes of those attempts were. And are you literally using `require nokogiri`? Are you sure you didn't actually use `require 'nokogiri'`? Have you tried completely removing rbenv and all its installed Rubies and gems, then reinstalling rbenv and Ruby and nokogiri? – anothermh Mar 29 '19 at 22:29
  • Will try removing & reinstalling rbenv. You are right that I'm using `require 'nokogiri'` – degenPenguin Mar 29 '19 at 23:19
  • Would `brew remove rbenv` completely remove everything as you suggest? – degenPenguin Mar 29 '19 at 23:22
  • 1
    I don’t know because I use RVM. Check the rbenv repo for instructions in safely removing and reinstalling. – anothermh Mar 29 '19 at 23:31
  • Thanks for the idea! I just decided to switch to RVM. it all works – degenPenguin Mar 29 '19 at 23:49

2 Answers2

1

Not really sure what the reason for the problem is, but switching to RVM fixed it.

In your terminal do the following:

  1. brew remove rbenv
  2. rm -rf ~/.rbenv
  3. \curl -sSL https://get.rvm.io | bash
  4. rvm install 2.5.1 (or the correct version number)
  5. rvm use 2.5.1 (or the correct version number
degenPenguin
  • 725
  • 1
  • 8
  • 23
0

You'll need to either change your GEM_HOME or do something like sudo gem install bundler -n /usr/local/bin.

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

That will only take effect for the current session, though. To make them more permanent, add those lines to your ~/.bashrc.

Jared Forth
  • 1,577
  • 6
  • 17
  • 32