Software⏱️ 3 min read📅 2026-06-03

How to Fix: Nokogiri installation fails -libxml2 is missing

Install libxml2 and libxslt to resolve Nokogiri installation issue.

Quick Answer: Try installing libxml2 and libxslt using the following command: sudo apt-get install libxml2 libxslt2-dev -y

Nokogiri installation fails with 'libxml2 is missing' error

This issue affects users who have installed Nokogiri without properly configuring their system dependencies.

🛑 Root Causes of the Error

  • The primary reason for this error is that libxml2 and its development libraries are not installed on the system.
  • Alternatively, it could be due to a mismatch between the required version of libxml2 and the installed version.

✅ Best Solutions to Fix It

Configuring System Dependencies

  1. Step 1: Install the necessary dependencies by running the command 'sudo apt-get install libxml2-dev' (for Ubuntu-based systems) or 'sudo yum install libxml2-devel' (for RHEL-based systems).
  2. Step 2: Update the package list by running 'sudo apt update' (for Ubuntu-based systems) or 'sudo yum update' (for RHEL-based systems).
  3. Step 3: Verify that the required dependencies are installed by checking the output of 'dpkg -s libxml2-dev' (for Ubuntu-based systems) or 'rpm -qa libxml2-devel' (for RHEL-based systems).

Using a Package Manager to Install Nokogiri

  1. Step 1: Use a package manager like Homebrew (on macOS) or apt-get (on Linux) to install the required dependencies and then run 'sudo gem install nokogiri' to install Nokogiri.
  2. Step 2: For example, on macOS with Homebrew, you can run 'brew install libxml2' followed by 'gem install nokogiri'.

✨ Wrapping Up

By following these steps, users should be able to resolve the 'libxml2 is missing' error and successfully install Nokogiri. If issues persist, it may be necessary to consult further resources or seek assistance from a system administrator.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions