title: Error installing nokogiri: Failed to build gem native extension & libiconv is missing (OSX)
body: <p>I try to clone <a href="https://github.com/crowdint/acts_as_shopping_cart_app" rel="noreferrer">this repo</a> and run <code>bundle install</code>. The bundle process failed and throw this error:</p>
  
  <pre><code>    ...
      Installing nokogiri 1.6.2.1 with native extensions
      Building nokogiri using packaged libraries.
  
      Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  
          /Users/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20151130-43880-pntnc6.rb 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/zulhilmizainudin/.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
  
      extconf failed, exit code 1
  
      Gem files will remain installed in /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/gems/nokogiri-1.6.2.1 for inspection.
      Results logged to /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.2.1/gem_make.out
      An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
      Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.
  </code></pre>
  
  <p>Then I try to run this:</p>
  
  <pre><code>gem install nokogiri -v '1.6.2.1'
  </code></pre>
  
  <p>And now I get this error:</p>
  
  <pre><code>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/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20151130-43942-1axq4sj.rb 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/zulhilmizainudin/.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
  
  extconf failed, exit code 1
  
  Gem files will remain installed in /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/gems/nokogiri-1.6.2.1 for inspection.
  Results logged to /Users/zulhilmizainudin/.rvm/gems/ruby-2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.2.1/gem_make.out
  </code></pre>
  
  <p>I tried to follow <a href="https://stackoverflow.com/a/6163052/1577357">this answer</a> but I still get the same error above.</p>
  
  <p>I also try to uninstall and install my brew again (<a href="https://stackoverflow.com/a/22439835/1577357">based on this answer</a>) and it's still same.</p>
  
  <p>Also, I try <a href="https://github.com/sparklemotion/nokogiri/wiki/Install-libiconv-on-OS-X-with-Homebrew" rel="noreferrer">this solution</a> but still get the error.</p>
  
  <p>What should I do now to make sure this nokogiri gem installed successfully?</p>
  
  <p>Note: I'm using OSX 10.11.1 El Capitan.</p>