Bullrico

Solving front-end and UX dilemmas

Installing Nokogiri After Updating Homebrew

I’m using OSX Lion, and after wrangling with updating Homebrew, my Rails 3 app wouldn’t start because of Nokogiri, so I tried manually installing it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ gem install nokogiri -v '1.5.2'
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/bobby/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
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-iconvlib

Gem files will remain installed in /Users/bobby/.rvm/gems/ruby-1.9.3-p194@app/gems/nokogiri-1.5.2 for inspection.
Results logged to /Users/bobby/.rvm/gems/ruby-1.9.3-p194@app/gems/nokogiri-1.5.2/ext/nokogiri/gem_make.out

To solve this, I followed part of the Nokogiri installation page and this StackOverflow thread. You have to brew install libxml2 and libxslt, brew link them, and install libiconv.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ brew install libxml2
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
######################################################################## 100.0%
######################################################################## 100.0%==> ./configure --prefix=/usr/local/Cellar/libxml2/2.8.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 program 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 its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxml2/2.8.0/lib
    CPPFLAGS -I/usr/local/Cellar/libxml2/2.8.0/include
==> Summary
/usr/local/Cellar/libxml2/2.8.0: 240 files, 10M, built in 78 seconds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ brew install libxslt
==> Downloading ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
######################################################################## 100.0%
######################################################################## 100.0%==> ./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.8.0
==> make
==> make install
==> Caveats
To allow the nokogiri gem to link against this libxslt, run

    gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this program 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 its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxslt/1.1.26/lib
    CPPFLAGS -I/usr/local/Cellar/libxslt/1.1.26/include
==> Summary
/usr/local/Cellar/libxslt/1.1.26: 143 files, 3.2M, built in 49 seconds
1
2
3
$ brew link libxml2 libxslt
Linking /usr/local/Cellar/libxml2/2.8.0... 16 symlinks created
Linking /usr/local/Cellar/libxslt/1.1.26... 24 symlinks created
1
2
3
4
5
$ brew install libiconv
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.

Manually install libiconv

1
2
3
4
5
6
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

Then (finally) install nokogiri:

1
2
3
4
5
$ gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
Fetching: nokogiri-1.5.5.gem (100%)
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.5.5
1 gem installed

Comments