Fastlane执行slather步骤报错:nokogiri要求Ruby版本≥2.3.0
I’ve dealt with similar environment mismatch headaches before—even when your system Ruby version clearly meets the requirement, tooling like Fastlane can sometimes pull from a different context. Here are practical, step-by-step fixes to get your fastlane metrics command working again:
1. Confirm Which Ruby Version Fastlane Is Actually Using
Your system Ruby might be 2.6.3, but Fastlane could be tapping into a separate Ruby environment (from rbenv, rvm, or an unmanaged gem set). Run this to check:
fastlane env
Look for the Ruby Version line in the output. If it doesn’t match 2.6.3, switch to your project’s correct Ruby version:
- For rbenv users:
rbenv local 2.6.3 - For rvm users:
rvm use 2.6.3
2. Use Bundler to Lock Dependencies (Most Reliable Fix)
Bundler ensures all gems (slather, nokogiri, and Fastlane itself) use versions compatible with your Ruby environment. Here’s how to set it up:
- Create a
Gemfilein your project root with this content:source "https://rubygems.org" gem "fastlane" gem "slather" - Install the locked dependencies:
bundle install - Run Fastlane through Bundler to enforce the correct environment:
bundle exec fastlane metrics
3. Reinstall Nokogiri and Slather to Fix Corrupted Installs
Sometimes gem installations get corrupted, even with the right Ruby version. Try a clean reinstall:
# Uninstall existing versions gem uninstall nokogiri slather # Reinstall nokogiri with system libraries (avoids macOS-specific build issues) gem install nokogiri --use-system-libraries gem install slather
If nokogiri still fails to install, make sure you have Xcode Command Line Tools up to date:
xcode-select --install
4. Update Xcode Command Line Tools
Outdated XCLT can cause hidden compatibility issues with Ruby gems like nokogiri. Verify your version:
xcode-select --version
If it doesn’t match your current Xcode version, update it via the command above or through Xcode’s Preferences > Locations tab.
5. Clear Cached Artifacts
Old build caches or gem leftovers might be interfering. Clean them up with:
# Clear Fastlane's build cache fastlane clean_build_cache # Remove outdated gem versions gem cleanup
Work through these steps in order—most of the time, either verifying the Ruby environment or using Bundler will resolve this confusing version mismatch error.
内容的提问来源于stack exchange,提问作者NicolasElPapu

