33

I'm having issues with bundling my Gemfile. I have Nokogiri installed already yet when I run bundle install it fails to load Nokogiri.

Installing Nokogiri:

gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.6.2
Parsing documentation for nokogiri-1.6.6.2
Done installing documentation for nokogiri after 2 seconds
1 gem installed

Bundle install:

bundle install   sic@ANTHONYs-iMac
Fetching gem metadata from https://rubygems.org/.........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.1
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Using activesupport 4.2.0
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2

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

    /Users/sic/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150312-7195-1d8tq46.rb extconf.rb 
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 packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv using --with-opt-* flags... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
  - 0001-Revert-Missing-initialization-for-the-catalog-module.patch
  - 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

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

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-apple-darwin14.1.0/ports/libxml2/2.9.2... OK
Running patch with /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-apple-darwin14.1.0/ports/libxml2/2.9.2/patch.log' to see what happened.
*** 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
  --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/sic/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
  --help
  --clean
  --use-system-libraries
  --enable-static
  --disable-static
  --with-zlib-dir
  --without-zlib-dir
  --with-zlib-include
  --without-zlib-include=${zlib-dir}/include
  --with-zlib-lib
  --without-zlib-lib=${zlib-dir}/lib
  --enable-cross-build
  --disable-cross-build
/Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
  from /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `chdir'
  from /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `execute'
  from extconf.rb:311:in `block in patch'
  from extconf.rb:308:in `each'
  from extconf.rb:308:in `patch'
  from /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:108:in `cook'
  from extconf.rb:278:in `block in process_recipe'
  from extconf.rb:177:in `tap'
  from extconf.rb:177:in `process_recipe'
  from extconf.rb:475:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/sic/home/ruby/rails/Vl2/vendor/bundle /ruby/2.2.0/extensions/x86_64-darwin-14/2.2.0/nokogiri-1.6.6.2/gem_make.out
An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.6.2'` succeeds before
bundling.`

My Gemfile contents:

source 'https://rubygems.org'

# Standard Rails gems
gem 'rails', '4.2.0'
gem 'sass-rails', '5.0.1'
gem 'uglifier', '2.7.1'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.5.3'
gem 'jbuilder', '2.2.11'
gem 'bcrypt', '3.1.10'


gem 'pg'
gem 'devise', '3.4.1'
gem 'redcarpet', '3.2.2'
gem 'kaminari', '0.16.3'
gem 'friendly_id', '5.1.0'
gem 'font-awesome-sass', '4.3.1'
gem 'bootstrap-sass', '3.3.3'


# OmniAuth
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-linkedin'

group :development, :test do
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'figaro', '1.1.0'
  gem 'spring', '1.3.3'
end



# Necessary for Windows OS (won't install on *nix systems)
gem 'tzinfo-data', platforms: [:mingw, :mswin]
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
T0ny lombardi
  • 1,800
  • 2
  • 18
  • 35

7 Answers7

51

Try running bundle config build.nokogiri --use-system-libraries as noted in the bundler output. Then re-run bundle.

Joe Van Dyk
  • 6,828
  • 8
  • 57
  • 73
  • Thanks! This solved the exact same issue on my Ubuntu server – Hugo Sequeira Jun 08 '16 at 15:00
  • It says something that it's quicker to search SO for this than to read the lengthy error log that __did__ contain this info – RichieAHB Jun 23 '16 at 16:28
  • Is there a way to ask Nokogiri to build against the packaged libxml 2.8.0? On OSX El Capitain, I get `WARNING: Nokogiri was built against LibXML version 2.9.2, but has dynamically loaded 2.8.0` – thesmart Jul 14 '16 at 16:24
  • This didn't work for me with macOS Sierra. Hiep Dinh's solution worked for me, though. – Linus Oct 10 '16 at 07:44
46
brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install

it's work for me

(source here)

Community
  • 1
  • 1
Hiep Dinh
  • 654
  • 5
  • 8
  • This fixed my issue but it seems that 'Postman' app is now broken. Seems related... – Chris J Allen Jun 07 '16 at 10:56
  • 1
    I use `gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2` insetad and it worked as well thanks – Pencilcheck Oct 21 '16 at 10:31
17

I had the same issues, but I solved it by installing nokogiri this way:

gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2

...then all was right with the world. I'll try:

bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2

...on my next rails app.

OS X 10.9.5

libxml2 2.9.2

Ruby 2.2.2

Rails 4.2.1

Nokogiri 1.6.6.2

Community
  • 1
  • 1
Abel
  • 2,115
  • 3
  • 18
  • 24
10

On Mac OSX, you can execute below commands to fix this nokogiri gem issue.

xcode-select --install
gem install nokogiri
bundle install
mainframer
  • 20,411
  • 12
  • 49
  • 68
  • Using Apple's libxml seems like the best way to go, if it is compatible. I suppose Apple is packaging 2.8.0? I believe Nokogiri includes 2.9.2. At app start, I get the warning: `WARNING: Nokogiri was built against LibXML version 2.9.2, but has dynamically loaded 2.8.0` – thesmart Jul 14 '16 at 16:26
4

I had the same issue, and I solved it with this:

sudo yum install patch
steco
  • 1,303
  • 13
  • 16
  • Awesome - this is the solution, because nokogiri has to patch it's vendor packed Version first. – bMalum Jul 19 '15 at 16:52
1
  • Issue is the location that bundler checking the Nokogiri.
  • Check which version of ruby using by your IDE and whether it is same as the global ruby version.
  • This fixed my issue which had with RubyMine.
ireshika piyumalie
  • 2,226
  • 22
  • 22
0

I noticed that I hadn't installed tar on my system. After running dnf install tar, gem install nokogiri went fine.

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
Dean Sims
  • 1
  • 1