Ruby gem build "checking for libxml-2.0 ... no" in CI
During a native gem install, mkmf probes for a system library and prints "checking for libxml-2.0 ... no" when it cannot find it. Nokogiri and similar gems then fail because the dependency they compile against is not available where they look.
What this error means
Installing nokogiri (or a libxml2/libxslt-backed gem) prints "checking for libxml-2.0 ... no" and aborts with guidance to install libxml2 or use the precompiled gem. The runtime library or its -dev package is missing or unfindable.
checking for libxml-2.0... no
ERROR: Failed to build gem native extension.
Please install libxml2 and libxslt development packages, or run:
gem install nokogiri -- --use-system-librariesCommon causes
libxml2/libxslt development packages are missing
The gem can use system libxml2 but the -dev packages providing headers and pkg-config metadata are not installed, so the check fails.
pkg-config cannot locate the library
The library is installed in a non-standard prefix that pkg-config does not search, so mkmf still reports "no".
How to fix it
Install the libxml2/libxslt dev packages
Provide the headers and pkg-config files mkmf is probing for.
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y libxml2-dev libxslt1-dev pkg-config
bundle install --jobs 4Use the precompiled nokogiri instead
Let Bundler install the platform-native nokogiri that bundles libxml2, avoiding the system probe entirely.
# ensure the platform variant is in the lockfile
bundle lock --add-platform x86_64-linux
bundle installHow to prevent it
- Prefer precompiled platform gems for nokogiri so no system libxml2 is needed.
- If building from source, install libxml2-dev, libxslt1-dev, and pkg-config in CI.
- Add the right platform to the lockfile so the precompiled gem is selected on CI.