3

I'm just getting going learning Rails and am struggling to get out of the blocks....

$ rails new sample_app
$ cd sample_app
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Using rake 10.5.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types 2.99
Using arel 6.0.3
Using debug_inspector 0.0.2
Using byebug 8.2.2
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using concurrent-ruby 1.0.0
Using multi_json 1.11.2
Using bundler 1.11.2
Using sass 3.4.21
Using tilt 2.0.2
Using spring 1.6.3
Using sqlite3 1.3.11
Using rdoc 4.2.2
Using tzinfo 1.2.2
Installing nokogiri 1.6.7.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.7.2/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160218-90999-1e1suiq.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
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.

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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config
    --with-xml2lib
    --without-xml2lib
    --with-libxml2lib
    --without-libxml2lib

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

  /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Users/pschloss/Desktop/rails/sample_app/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-15/2.0.0/nokogiri-1.6.7.2/gem_make.out
Using rack-test 0.6.3
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using sprockets 3.5.2
Using sdoc 0.4.1
Using activesupport 4.2.5.1
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

So then I finally get nokogiri installed...

$ gem install nokogiri -- --use-system-libraries
Building native extensions with: '--use-system-libraries'
This could take a while...
Successfully installed nokogiri-1.6.7.2
Parsing documentation for nokogiri-1.6.7.2
Done installing documentation for nokogiri after 1 seconds
1 gem installed

And then I redo bundle install and I get the same error I had before.

Also if I do:

$ bundle config build.nokogiri --use-system-libraries & bundle install

I get the same errors.

Here are some specs:

$ rails --version
Rails 4.2.5.1
$ ruby --version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.11.1
BuildVersion:   15B42

Any ideas on what I'm doing wrong here?

Pat S
  • 490
  • 4
  • 15

2 Answers2

2

I'll try to give a bit of background information (since you're just starting out and this might help with the ride).

In Ruby and Rails land you'll be installing a lot of gems ("libraries"). Sometimes libraries need/want to be fast and therefore a part of the gem is written in C. Installing these parts can be difficult, thats whats happening at

Installing nokogiri 1.6.7.2 with native extensions

These native extensions need to be compiled and dynamically linked and have gained a reputation for being complicated to install so this might happen more often than you'd like :(.

In Nokogiris case though, you are lucky since they have a whole page dedicated to fixing installation issues here.

To get to your case, the regular gem install works, my guess is you need to tell bundler to use system libraries

export NOKOGIRI_USE_SYSTEM_LIBRARIES=1
bundle install

Edit:

I missed that you were already specifying that, maybe try:

--with-xml2-include=/wherever/brew/install/it

and have a look here.

Community
  • 1
  • 1
wpp
  • 7,093
  • 4
  • 33
  • 65
  • Thanks, but I get the same error. Isn't that effectively the same thing as what I did with `bundle config build.nokogiri --use-system-libraries & bundle install`? – Pat S Feb 18 '16 at 21:52
  • Oh shoot, I missed that! Sorry. Have you tried the `--with-xml2-include=/wherever/brew/install/it` flag? Otherwise try this [thread for suggestions](http://stackoverflow.com/questions/23668684/failed-to-build-gem-native-extension-when-i-run-bundle-install) – wpp Feb 18 '16 at 22:00
  • 1
    Thanks for the link to that thread, turned out that http://stackoverflow.com/a/25068003/3914395 had the solution: `brew install libxml2 bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2" bundle install` - I wasn't using both `--use-system-libraries` and `--with-xml2-include` together. – Pat S Feb 18 '16 at 22:28
  • @PatS Glad to hear that. I've updated my answer so folks don't have to look in the comments. – wpp Feb 18 '16 at 22:34
0

Your OS is lacking of some libraries like libxml2. So try:

brew install libxml2
brew install libxslt
zeitnot
  • 1,304
  • 12
  • 28
  • Thanks for the help, but that doesn't change anything. I'm able to get the gem installed without bundle by doing `gem install nokogiri -- --use-system-libraries`, it's just that bundle doesn't recognize that. – Pat S Feb 18 '16 at 21:45