解决 Mac OS 10.14 环境下 gem install ERROR

环境

  • Mac OS Mojave 10.14
  • ruby 2.3.7p456 (2018-03-28 revision 63024)

报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
$ sudo gem install sass
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191022-2775-1q9uxye.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.11.1/gem_make.out

解决方法

如果是之前的 Mac OS 版本,网上都是通过 xcode-select --install 来解决,但是我在 Mac OS 10.14 版本下,依然存在报错。

最终找到解决方式,执行:

1
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

然后根据提示安装即可。

参考链接:https://github.com/castwide/vscode-solargraph/issues/78