Software⏱️ 2 min read📅 2026-05-31

How to Fix: Why does installing Nokogiri on Mac OS fail with libiconv is missing?

Nokogiri installation fails on Mac OS due to missing libiconv. Solution: Install libiconv using Homebrew.

Quick Answer: Install libiconv using Homebrew with the command 'brew install libiconv' and try installing Nokogiri again.

Installing Nokogiri on Mac OS can fail due to the missing libiconv library. This issue occurs because the --with-iconv-include and --with-iconv-lib options are set to include and link against the wrong locations of the libiconv library.

✅ Best Solutions to Fix It

Method 1: Update Homebrew and Install libiconv

  1. Step 1: Run the command brew update to update Homebrew.

Method 2: Install libiconv using MacPorts or Homebrew

  1. Step 1: Run the command port install iconv to install libiconv using MacPorts.

Method 2 (Alternative): Install libiconv using Homebrew

  1. Step 1: Run the command brew install iconv to install libiconv using Homebrew.

After installing libiconv, try running the original command again with the updated --with-iconv-include and --with-iconv-lib options. The correct locations should be /usr/local/opt/iconv/include and /usr/local/opt/iconv/lib.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions