OS X Lion, Attempting Nokogiri install - libxml2 is missing
Asked Answered
S

17

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

        /Users/sajeev86/.rvm/rubies/ruby-1.8.7-p352/bin/ruby extconf.rb
checking for libxml/parser.h... no
-----
libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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.

I can't get Nokogiri to install. This has been taxing me for a while now. I've installed the dependencies via MacPorts and Homebrew as well.

I've got a feeling the right directories are not pointed to each other? But haven't a clue how to fix.

Semination answered 3/2, 2012 at 19:32 Comment(0)
B
43

In Mavericks, installing the libraries with Homebrew and setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before installing the gem did the trick for me.

Summarising:

  • If previously installed, uninstall the gem:
    $ gem uninstall nokogiri

  • Use Homebrew to install libxml2, libxslt and libiconv:
    $ brew install libxml2 libxslt libiconv

  • Install the gem specifying the paths to the libraries to be linked against:
    $ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

Burnout answered 10/5, 2014 at 19:5 Comment(2)
export NOKOGIRI_USE_SYSTEM_LIBRARIES=1 also helped my bundle install, thanks.Forgot
I did not have to uninstall nokogiri, and since I'm using port simply tried NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri, which did the trick for meBandwagon
T
32

Absolutely none of the other answers here worked for me.

On the latest version of Mavericks, the only method that succeeded for me was the following:

$ brew install libxml2 libxslt libiconv
$ sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib
Thaine answered 12/12, 2014 at 1:5 Comment(3)
At least as of today, that brew command fails as there is "No available formula for libiconv" (plus a recommendation just to use the copy Apple supplies). The suggested gem line then fails with the same "failed to build gem native extension".Alpha
OK, Tommy... no problem. Try installing libiconv manually, and then remove that one word from the brew install line. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz; tar xvfz libiconv-1.13.1.tar.gz; cd libiconv-1.13.1; ./configure --prefix=/usr/local/Cellar/libiconv/1.13.1; make; sudo make install; Thaine
This worked on High Sierra /w noko version 1.8.2 as well.Fletcher
K
16

Same issue happened to me on Lion. Took hours of reading posts, trying homebrew, macports, etc. When I found this post and read the contents of .rvm/gems/ruby-1.8.7-p358/gems/nokogiri-1.4.4/ext/nokogiri/mkmf.log, I saw:

find_header: checking for libxml/parser.h... -------------------- no

"/usr/bin/gcc-4.2 -E -I. -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/i686-darwin10.8.0 -I. -I-I-I/opt/local/include -I-I-I/usr/local/include -I-I-I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I-I-I/usr/include -I-I-I/usr/include/libxml2 -I/opt/local/include/libxml2 -I/usr/local/include/libxml2 -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include/libxml2 -I-I/opt/local/include -I-I/usr/local/include -I-I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I-I/usr/include -I-I/usr/include/libxml2 -I/opt/local/include -I/usr/local/include -I/Users/me/.rvm/rubies/ruby-1.8.7-p358/include -I/usr/include -I/usr/include/libxml2  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -g -O2  -fno-common -pipe -fno-common    -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline  conftest.c -o conftest.i"
checked program was:
/* begin */
1: #include <libxml/parser.h>
/* end */

However, gcc-4.2 didn't exist:

$ ls /usr/bin/gcc*
/usr/bin/gcc

Hence, I was able to solve the issue and get nokogiri to install by making a gcc-4.2 a symlink to gcc.

sudo ln -s gcc gcc-4.2
Ketchup answered 25/7, 2012 at 23:47 Comment(0)
S
10

I ran into same issue for Mavrick and solution was the

xcode-select --install

However that was not working as apple download page does not have that installer available publically. So if you want to have the command-line tools for Mavricks you need to have a paid account then only you will be able to install it. Once you install it you will not face this issue of Nokogiri.

Supervision answered 26/11, 2013 at 8:2 Comment(0)
G
9

Checking the url given in the error message (http://nokogiri.org/tutorials/installing_nokogiri.html) I think the question is what version of Homebrew are you using?

brew -v

I'd update to 0.8+

brew update
brew upgrade

and then try the installation again:

brew install libxml2 libxslt
brew link libxml2 libxslt
gem install nokogiri
Gaillardia answered 3/2, 2012 at 19:56 Comment(4)
I have not encountered that problem before, can you try to first "brew unlink libxml2" and then "brew link libxml2"Gaillardia
Linking /usr/local/Cellar/libxml2/2.7.8... 21 symlinks created Linking /usr/local/Cellar/libxslt/1.1.26... 22 symlinks created But it still returns the libxml2 is missing message.Semination
When I try brew link libxml2 libxslt, I get an error saying it "Refused to link macOS provided/shadowed sooftware"Harrietharriett
Does the install succeed? no weird error messages? (brew install libxml2 libxslt)Gaillardia
C
7

As for me, it helps:

brew install libxml2 libxslt

if permission denied sudo chown -R $USER /Library/Caches/Homebrew

sudo env ARCHFLAGS="-arch x86_64"

export NOKOGIRI_USE_SYSTEM_LIBRARIES=1

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri
Crigger answered 14/8, 2015 at 15:26 Comment(0)
M
6
brew install libxml2 libxslt 
gem install nokogiri -v '1.6.5' -- --use-system-libraries
Mikiso answered 3/12, 2014 at 4:5 Comment(1)
It would be nice if you explained to the OP what is going on here, and why it works. You know, "teach a man to fish" and all that.Tony
C
3

Late to the party, but in case anyone is still having this issue while using MacPorts:

Add the /include dir to your PATH in your .profile file so nokogiri knows where to find it.

e.g.

MacPorts writes to your .profile file and adds the following line by default:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

First, add the /include path like so:

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/include/:$PATH

Then, run this from the same terminal window:

source ~/.profile

(this tells your terminal to recheck the .profile file for any changes)

Finally, try installing the gem from the same terminal window.

sudo gem install nokogiri
Communion answered 24/4, 2012 at 17:5 Comment(0)
C
3

On Yosemite I used:

brew install libxml2 libxslt
sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib

Very close to some of the above commands but without the libconv

Coronagraph answered 4/2, 2015 at 5:36 Comment(0)
A
2

For my somewhat outdated system encountering the issues above, specifically:

FENG-SHUI:demo Eric$ brew install libxml2
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.9.0.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching patching file threads.c patching file xpath.c
==> ./configure --prefix=/usr/local/Cellar/libxml2/2.9.0 --without-python
==> make
==> make install
==> Caveats This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in parallel can cause all kinds of trouble.

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

    LDFLAGS:  -L/usr/local/opt/libxml2/lib
    CPPFLAGS: -I/usr/local/opt/libxml2/include

Error: Failed to create: /usr/local/opt/libxml2 
Things that depend on libxml2 will probably not build.
    ==> Summary /usr/local/Cellar/libxml2/2.9.0: 273 files, 11M, built in 2.0 minutes 

FENG-SHUI:demo Eric$ brew install libxml2 libxslt 
Error: libxml2-2.9.0 already installed 
Error: /usr/local/opt/libxml2 not present or broken Please reinstall libxml2. Sorry :(

This was the magic formula for getting libxml2 and libxslt happily running:

# latest version 2.9.0
brew install libxml2

# installing libxslt from source code
# get latest libxslt from ftp://xmlsoft.org/libxml2/libxslt-git-snapshot.tar.gz..
# then
./configure --prefix=/usr/local/Cellar/libxslt/1.1.28 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.9.0
make
sudo make install

# installing nokogiri with this new compiled libs
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28

Thanks to this guy: https://gist.github.com/fabioyamate/443160

Hope this helps someone!

Alphabetize answered 4/4, 2013 at 5:45 Comment(2)
This worked for installing nokogiri 1.6.0 on OSX 10.8.4 with libxslt 1.1.28 and libxml2 2.9.1 – thanks!Habergeon
threads.c:918:20: error: expected expression once_control = PTHREAD_ONCE_INIT; ^ /usr/include/pthread.h:203:27: note: expanded from macro 'PTHREAD_ONCE_INIT' #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}Kristianson
C
1

Try adding --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib to your command, assuming that's where MacPorts libxml2.

Combination answered 3/2, 2012 at 19:37 Comment(0)
H
1

I struggled with this for hours until I found this blogpost: http://www.markhneedham.com/blog/2010/07/08/installing-ruby-1-9-2-with-rvm-on-snow-leopard

Running the command

file /usr/local/lib/libxml2.2.dylib

in the terminal returned

/usr/local/lib/libxml2.2.dylib: Mach-O dynamically linked shared library i386

which means my libxml2.2 was compiled for a 32 bit system, so I had to recompile libxml2 for 64 bit OS (Lion)

First I downloaded LATEST_LIBXML2 from ftp://xmlsoft.org/libxml2 and ran the following commands:

tar xzvf LATEST_LIBXML2

cd libxml2-2.8.0

./configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.3/

make

Then I downloaded LATEST_LIBXSLT from the same site and ran these commands:

tar xzvf LATEST_LIBXSLT

cd libxslt-1.1.26

./configure

make

sudo make install

Running

file /usr/local/lib/libxml2.2.dylib

again returned

/usr/local/lib/libxml2.2.dylib: Mach-O 64-bit dynamically linked shared library x86_64

And I could finally install nokogiri!

Heterocercal answered 4/6, 2012 at 14:10 Comment(0)
S
1

This worked for me on OSX - the same as @remeberer's answer, but with a full path.

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Semiaquatic answered 3/9, 2013 at 18:6 Comment(0)
Y
1

I had to use this command for it to work :

sudo gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries

(source : http://www.virtlab.cx/ruby-fix-error-install-nokogiri-yosemite/ , many thanks to the author)

Yalu answered 21/4, 2015 at 8:23 Comment(0)
R
0

ran into a similar install issue on mountain lion except the make command was looking for gcc-4.2 in /usr/local/opt/apple-gcc42/bin

this resolved the issue for me; no need to brew install libxml2 or libxslt or add a --with option:

mkdir -p /usr/local/opt/apple-gcc42/bin
ln -s /usr/bin/gcc /usr/local/opt/apple-gcc42/bin/gcc-4.2
Raffin answered 1/5, 2014 at 10:10 Comment(0)
B
0

If you're installing an older version of Nokogiri, i.e. pre 1.6, this may help:

In the Nokogiri installation guide, they mention:

Because Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for being complicated to install.

As of Nokogiri 1.6, libxml2 and libxslt source code is bundled with Nokogiri, and compiled at gem-install-time. This document should work for all versions 1.6.4 and later.

(If you need support for installing earlier versions of Nokogiri, you may want to take a look at the git history for this document.)

Indeed, it is difficult to install, but there is a way. I went digging through the history of the readme, and decided on this one, with the well-written commit message:

"Homebrew, I straight hate you."

From that message and from the other answers here, I gleaned that I needed to be very specific about libxml2's lib, dir and include directories when installing Nokogiri. The following worked for me, but please update to match your version of the libxml2 software (mine was 2.9.2 and I was installing Nokogiri 1.5.0):

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -v '1.5.0' -- 
    --use-system-libraries 
    --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib 
    --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" 
    --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config" 
    --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.2/ 
    --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2
Bonnie answered 7/4, 2015 at 2:4 Comment(0)
D
0

For me, I simply did the following

xcode-select --install
gem install nokogiri

For more in-depth troubleshooting, checkout Installing Nokogiri

Doubleton answered 3/4, 2017 at 0:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.