How to resolve can't find header files for ruby error when install cocoapods in macos
Problem
When installing cocoapods on macOS using the following command:
The following error occurs:
The error indicates that the Ruby header files are missing, which prevents the installation of the ffi
gem, a dependency for cocoapods.
Environment
- macOS 10.14
- Ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
- Gem 2.5.2.3
Reason
The root cause of this issue is that Xcode 11 ships with the macOS 10.15 SDK, which includes headers for Ruby 2.6 but not for macOS 10.14’s Ruby 2.3. This mismatch causes the mkmf.rb
script to fail when trying to locate the Ruby header files.
To verify the issue, check the Ruby configuration:
This command outputs a directory path that does not exist:
Solution
To resolve this issue, update the Ruby configuration to point to the correct SDK path:
After running this command, verify the updated Ruby header directory:
The output should now point to the correct path:
Now, retry installing cocoapods:
The installation should proceed without errors.
The Last Step
After successfully installing cocoapods, restore the original Xcode settings:
Summary
This post walked through the steps to resolve the “can’t find header files for ruby” error when installing cocoapods on macOS. The issue arises due to a mismatch between the Ruby version and the SDK headers provided by Xcode. By updating the Ruby configuration to point to the correct SDK path, the installation process can proceed smoothly. Remember to restore the original Xcode settings after completing the installation to avoid unintended side effects.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!