Reputation: 8386
I know there are a lot of questions about this gem but no answer has worked for me.
When I run in SSH gem install nokogiri
I get this error:
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/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.
My host told me that all libs are installed. Here are the full logs after executing the install nokogiri command:
Building native extensions. This could take a while...
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:
gem install nokogiri -- --use-system-libraries
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
However, note that nokogiri does not necessarily support all versions
of libxml2.
For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/opt/rubies/ruby-1.9.3/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... yes
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:
gem install nokogiri -- --use-system-libraries
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
However, note that nokogiri does not necessarily support all versions
of libxml2.
For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/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
--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=/opt/rubies/ruby-1.9.3/bin/ruby
--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
/home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `chdir'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `execute'
from extconf.rb:282:in `block in patch'
from extconf.rb:279:in `each'
from extconf.rb:279:in `patch'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:108:in `cook'
from extconf.rb:253:in `block in process_recipe'
from extconf.rb:154:in `tap'
from extconf.rb:154:in `process_recipe'
from extconf.rb:419:in `<main>'
Upvotes: 73
Views: 58595
Reputation: 7826
2020 April 6th Update:
macOS Catalina 10.15
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2/
macOS Mojave 10.14
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2/
macOS High Sierra 10.13
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/
macOS Sierra 10.12:
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/
OS X El Capitan 10.11
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/
Consider to add sudo
if you don't have permission.
For some reason Apple’s Yosemite version of OSX does not have a system accessible installation of libxml2. Nokogiri requires this in order to compile and luckily Xcode has a version of libxml2 bundled with it — we just need to specify it when installing the gem. It’s important to get Nokogiri installed correctly because as of right now Rails 4.2.1.rc4 automatically attempts to install it and you will feel pain.
Upvotes: 144
Reputation: 935
If using bundler, run this command first:
bundle config build.nokogiri --use-system-libraries
Upvotes: 0
Reputation: 2572
step 1:
brew install libxml2
Step 2:
bundle config build.nokogiri --use-system-libraries
Step 3: then try
bundle install
Upvotes: 2
Reputation: 714
I figured this out the hard way and took a few hours to follow the breadcrumbs and read up on what people were trying out. Nothing helped. Everything on this overflow page just didn't help so here's how I fixed this:
If you use your machine for other development projects that aren't in ruby
. You might want to check package manager installations for other languages. More importantly - you might want to check for other c compiler installations - namely clang
In my case - I had installed anaconda/conda(python)
and this replaced a bunch of paths in my .bash_profile
to use clang
as the main c compiler where as xcode command line tools
and rebenv
were all using gcc
installed through Homebrew earlier.
I removed anaconda(using anaconda-clean)
and the clang
installation and then tried to bundle. That's when I got the missing libxml2
issue. I then REINSTALLED libxml2
through homebrew to ensure the symlinks would be redone through homebrew
and followed the instructions that followed to add the appropriate export flags
to my ~/bash_profile
file.
Successfully bundles now. The reason is, the gems are now being bundled with the same compiler as the ruby version I am using for that project.
Docker would have made this a non issue for a polyglot dev machine like many of us I assume.
So heads up.
Upvotes: 2
Reputation: 3
In my case, I am using Mac OSX Mojave and had to install a package described here: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035624
Here is the path to the package: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After installing it, the installation finished without problems.
Upvotes: 0
Reputation: 2028
Nokogiri didn't find Xcode libs on my OSX Sierra machine until I ran:
sudo xcodebuild -license accept
Upvotes: 3
Reputation: 1096
brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install
It working for me :)
Upvotes: 3
Reputation: 157
Am using macOS Sierra.
Went to nokogiri documentation and followed this:
ON MAC OSX
Installation should Just Work™ using Nokogiri’s vendored libxml2 and libxslt.
First, make sure you have the latest version of RubyGems and xcode commandline tools:
1 gem update --system
2 xcode-select --install
Then install nokogiri:
1 gem install nokogiri
Upvotes: -2
Reputation: 1247
Nothing in current answers worked for me (I use Ubuntu 16.04, not Mac).
However, by following the instructions in Nokogiri site and this part did the trick:
# See http://www.nokogiri.org/tutorials/installing_nokogiri.html#ubuntu___debian
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev
Note I've been using Nokogiri since 2009 and I've always had trouble installing it. Any further comment would probably not comply with SO T&Cs :)
Upvotes: 4
Reputation: 90
Just Like wongzigii says the install command works with those flags with macOS Sierra
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/
Upvotes: 2
Reputation: 31
Finally after much struggle the following worked for me (OS X 10.8.5, macports). (I am installing github pages i.e. jekyll)
/opt/local/bin/gem install nokogiri -v 1.6.6.2 -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib
Upvotes: 0
Reputation: 636
This works for me in Windows 7 Home Basic 64 Bit:
gem install nokogiri -v 1.6.2.1 -- --use-system-libraries
Upvotes: 4
Reputation: 47
This worked for me:
sudo gem install nokogiri -v 'versionNumber' -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib
Upvotes: 1
Reputation: 8386
Finally, the problem was caused by nokogiri itself by shipping it's own libxml2 that's incompatible with some systems.
So to install nokogiri I had to tell it that it should use the system libraries.
I installed it manually by:
gem install nokogiri -v 1.6.2.1 -- --use-system-libraries
And it worked well. Other answers didn't solve it.
Upvotes: 55
Reputation: 26947
This is what worked for me on OS X 10.10.3 Yosemite:
sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib
Upvotes: 2
Reputation: 19723
On OSX Yosemite, I did xcode-select --install
in a terminal. After which, bundle
worked fine with that gem.
Upvotes: 18
Reputation: 11107
This worked for me with OS X Yosemite.
gem install nokogiri -v 1.6.5 -- --use-system-libraries
Upvotes: 3
Reputation: 3699
I ran into this same problem, because of an unlisted build dependency. When I found the tmp directory in question:
find ~/.rbenv/ -name patch.log
It said:
sh: patch: command not found
Fixed that with a simple:
sudo yum install -y patch
Upvotes: 24