gem install - fatal error: 'ruby/config.h' file not found in Catalina

记录一下安装cocoapods失败的问题。
新电脑,好久没用cocoapods了,新用到了一个库需要装一下cocoapods,结果
sudo gem install cocoapods
的时候报错了,错误就是标题那样的:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found

OK,既然问题来了,那就search吧,在这里找到了答案:

image.png

也就是用xcrun工具安装:xcrun gem install cocoapods,原因截图里也说明了。
但是直接这么run有可能会报这个错:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

所以加上sudo就行:sudo xcrun gem install cocoapods

总结

搜索大法好!

你可能感兴趣的:(gem install - fatal error: 'ruby/config.h' file not found in Catalina)