Instantly share code, notes, and snippets.

Embed
What would you like to do?
# using rvm with ruby-1.8.7-p249
# latest version 2.7.7 2010-06-17
brew install libxml2
# installing libxslt from source code
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar xvfz libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.7
make
sudo make install
# installing nokogiri with this new compiled libs
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
@sekrett

This comment has been minimized.

Show comment
Hide comment
@sekrett

sekrett Oct 3, 2011

libxml is 2.7.8 now and it works too

sekrett commented Oct 3, 2011

libxml is 2.7.8 now and it works too

@oscarcck

This comment has been minimized.

Show comment
Hide comment
@oscarcck

oscarcck Dec 19, 2011

this save me half of the problem~
another half, Gemfile & bundle install problem
below is the fix

$ bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26

of course, need change the version

credit : https://gist.github.com/1344331

oscarcck commented Dec 19, 2011

this save me half of the problem~
another half, Gemfile & bundle install problem
below is the fix

$ bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26

of course, need change the version

credit : https://gist.github.com/1344331

@shenry

This comment has been minimized.

Show comment
Hide comment
@shenry

shenry Dec 23, 2011

Thanks for the gist, I had to add

--with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

... apparently in my case the problem really was libiconv.

shenry commented Dec 23, 2011

Thanks for the gist, I had to add

--with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

... apparently in my case the problem really was libiconv.

@sjtipton

This comment has been minimized.

Show comment
Hide comment
@sjtipton

sjtipton Jan 31, 2012

Thank you, and for me on OSX 10.7.2 Lion, I needed:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

Wiping the sweat off my brow...

sjtipton commented Jan 31, 2012

Thank you, and for me on OSX 10.7.2 Lion, I needed:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.7/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.7/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

Wiping the sweat off my brow...

@Sivli-Embir

This comment has been minimized.

Show comment
Hide comment
@Sivli-Embir

Sivli-Embir Feb 8, 2012

@sjtipton you are a life saver! For others that follow this will work for OS X 10.7.2
running with ruby 1.9.3p0
currently libxml2 2.7.8

brew install libxml2

follow above but adjust accordingly
installing libxslt from source code

wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar xvfz libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.8
make
sudo make install

If your like me and did not think to check if you had libiconv 1.14 <-- be sure this is current

brew install libiconv

Finally

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

Thanks to the above commenters!

Sivli-Embir commented Feb 8, 2012

@sjtipton you are a life saver! For others that follow this will work for OS X 10.7.2
running with ruby 1.9.3p0
currently libxml2 2.7.8

brew install libxml2

follow above but adjust accordingly
installing libxslt from source code

wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar xvfz libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.8
make
sudo make install

If your like me and did not think to check if you had libiconv 1.14 <-- be sure this is current

brew install libiconv

Finally

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

Thanks to the above commenters!

@wolfdancer

This comment has been minimized.

Show comment
Hide comment
@wolfdancer

wolfdancer Feb 8, 2012

Thank you so much for the instruction!

I also want to add a bit side comment: If you upgrade to Mac OS Lion AFTER you install the RVM, ruby, DevCoder, you need to refresh them: http://www.fakingfantastic.com/2010/11/26/fixing-the-you-have-to-install-development-tools-first-error-with-nokogiri/

wolfdancer commented Feb 8, 2012

Thank you so much for the instruction!

I also want to add a bit side comment: If you upgrade to Mac OS Lion AFTER you install the RVM, ruby, DevCoder, you need to refresh them: http://www.fakingfantastic.com/2010/11/26/fixing-the-you-have-to-install-development-tools-first-error-with-nokogiri/

@MugOfPaul

This comment has been minimized.

Show comment
Hide comment
@MugOfPaul

MugOfPaul Dec 24, 2012

I've found libiconv lurking in my libxslt. And the Nokogiri installation instructions only recommend you instal libxml2 and libxslt. So on my (pretty standard) OS X Mountain Lion install, this works for me:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libxslt/1.1.26/include --with-iconv-lib=/usr/local/Cellar/libxslt/1.1.26/lib

I really try to avoid gems that depend on Nokogiri because this always trips me up and I find it incredibly annoying.

MugOfPaul commented Dec 24, 2012

I've found libiconv lurking in my libxslt. And the Nokogiri installation instructions only recommend you instal libxml2 and libxslt. So on my (pretty standard) OS X Mountain Lion install, this works for me:

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libxslt/1.1.26/include --with-iconv-lib=/usr/local/Cellar/libxslt/1.1.26/lib

I really try to avoid gems that depend on Nokogiri because this always trips me up and I find it incredibly annoying.

@haggen

This comment has been minimized.

Show comment
Hide comment
@haggen

haggen Jun 4, 2014

Nothing worked with me.

$ brew install libiconv

Returns:

Error: No available formula for libiconv
Apple distributes libiconv with OS X, you can find it in /usr/lib.
Some build scripts fail to detect it correctly, please check existing
formulae for solutions.

And any attempt to build libiconv from source returns:

builddir="`pwd`"; cd libcharset && /Applications/Xcode.app/Contents/Developer/usr/bin/make all && /Applications/Xcode.app/Contents/Developer/usr/bin/make install-lib libdir="$builddir/lib" includedir="$builddir/lib"
/bin/sh: line 0: cd: libcharset: No such file or directory
make: *** [lib/localcharset.h] Error 1

haggen commented Jun 4, 2014

Nothing worked with me.

$ brew install libiconv

Returns:

Error: No available formula for libiconv
Apple distributes libiconv with OS X, you can find it in /usr/lib.
Some build scripts fail to detect it correctly, please check existing
formulae for solutions.

And any attempt to build libiconv from source returns:

builddir="`pwd`"; cd libcharset && /Applications/Xcode.app/Contents/Developer/usr/bin/make all && /Applications/Xcode.app/Contents/Developer/usr/bin/make install-lib libdir="$builddir/lib" includedir="$builddir/lib"
/bin/sh: line 0: cd: libcharset: No such file or directory
make: *** [lib/localcharset.h] Error 1
@pkpp1233

This comment has been minimized.

Show comment
Hide comment
@pkpp1233

pkpp1233 Jul 8, 2014

same problem as haggen

pkpp1233 commented Jul 8, 2014

same problem as haggen

@arojoal

This comment has been minimized.

Show comment
Hide comment
@arojoal

arojoal Jul 9, 2014

same problem for me.

Building native extensions. This could take a while...
Building nokogiri using packaged libraries.
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

/Users/rojalval/.rvm/rubies/ruby-2.0.0-p481/bin/ruby extconf.rb

Building nokogiri using packaged libraries.

libiconv 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.

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/rojalval/.rvm/rubies/ruby-2.0.0-p481/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

extconf failed, exit code 1

arojoal commented Jul 9, 2014

same problem for me.

Building native extensions. This could take a while...
Building nokogiri using packaged libraries.
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

/Users/rojalval/.rvm/rubies/ruby-2.0.0-p481/bin/ruby extconf.rb

Building nokogiri using packaged libraries.

libiconv 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.

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/rojalval/.rvm/rubies/ruby-2.0.0-p481/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

extconf failed, exit code 1

@arojoal

This comment has been minimized.

Show comment
Hide comment
@arojoal

arojoal Jul 9, 2014

I've solved it by installing XCode ComandLine tools:

xcode-select --install

arojoal commented Jul 9, 2014

I've solved it by installing XCode ComandLine tools:

xcode-select --install

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Aug 12, 2014

@arojoal
Thanks for:
xcode-select --install

It solved the problem for me too

ghost commented Aug 12, 2014

@arojoal
Thanks for:
xcode-select --install

It solved the problem for me too

@SteveBenner

This comment has been minimized.

Show comment
Hide comment
@SteveBenner

SteveBenner Aug 18, 2014

As a self-contained solution, I wrote a Ruby script that just installs Nokogiri using Homebrew's libraries instead of Apple's. It seems to flawlessly solve the issue on normal systems; I've used it twice without any issues. You can choose whether to install using either RubyGems or Bundler. Contributions or suggestions are welcome!

SteveBenner commented Aug 18, 2014

As a self-contained solution, I wrote a Ruby script that just installs Nokogiri using Homebrew's libraries instead of Apple's. It seems to flawlessly solve the issue on normal systems; I've used it twice without any issues. You can choose whether to install using either RubyGems or Bundler. Contributions or suggestions are welcome!

@ananth99

This comment has been minimized.

Show comment
Hide comment
@ananth99

ananth99 Mar 16, 2015

I can confirm xcode-select --install worked for me. Thanks @arojoal

ananth99 commented Mar 16, 2015

I can confirm xcode-select --install worked for me. Thanks @arojoal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment