macOS 下安装 Sass 失败

某日在使用 Koala 编译时 Sass 报错,之前一直正常使用,回忆起前两天系统更新到 macOS High Sierra 猜测症结在此。为了解决这个问题花了我一个多小时,甚至差点耽误项目上线,实在可恶,在此记录一下。
macOS High Sierra

  1. 尝试重新安装 Koala 解决。无效
  2. 尝试重新安装 Sass,出现报错
brew install sass

出错信息:

Building native extensions.  This could take a while...
ERROR:  Error installing sass:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/ffi-1.9.18/ext/ffi_c
/usr/bin/ruby2.3 -r ./siteconf20170807-17063-1bg5m1e.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/ffi-1.9.18 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/ffi-1.9.18/gem_make.out

只能祭出 Google 大法了,不过网络上提供的以下方式也是无效的:

sudo brew install ruby-dev

尝试重新安装,错误依旧,期间各种折腾也是无功而返,最终搜索到关键词可能与 Xcode Command Line Tools 有关,因为升级过 macOSXcode Command Line Tools 需要重新安装。运行以下命令,然后等待安装完毕即可。

xcode-select --install

为了保险起见,最后重新执行一些列安装操作(记得更换为 RubyGems 的镜像)。最终大功告成!

brew istall ruby
gem install sass

BTW:期间各种折腾,包括使用系统自带 Ruby 会提示权限错误,用 Homebrew 安装的 Ruby 替代可避免。

ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /usr/local/lib/ruby/gems/2.4.0/gems/sass-3.5.1/.yardopts

总结:如 macOS 有升级一定要检查 Xcode Command Line Tools 是否需要重新安装!!!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注