【问题标题】:Error while installing Jekyll on Mac OSX 10.8.2在 Mac OSX 10.8.2 上安装 Jekyll 时出错
【发布时间】:2013-01-27 22:24:14
【问题描述】:

我是 Ruby 新手,对命令行也比较陌生。我正在尝试安装 Jekyll 来构建静态站点,但遇到了一些问题。我安装了 Ruby v. 1.8.7 和 Ruby Gems v. 1.8.25,但运行时出现此错误:

$ sudo gem install jekyll

我明白了:

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

    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/fast-stemmer-1.0.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/fast-stemmer-1.0.1/ext/gem_make.out

谁能告诉我如何安装 ruby​​ 的头文件?我需要将它们安装在特定目录中吗?我是否需要在其他目录中完全重新安装 Ruby,因为这是我的 Mac 附带的原始安装/设置?

更新

我已经安装了 XCode 并安装了 RVM,但我无法超越这一点。当我尝试安装 Ruby 时,我得到了这个:

Daniels-MacBook-Air:~ danielrosenthal$ rvm -v

rvm 1.18.3 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

Daniels-MacBook-Air:~ danielrosenthal$ rvm install 1.8.7
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.8.7-p371.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.
Daniels-MacBook-Air:~ danielrosenthal$ rvm requirements
Requirements for osx/10.8/x86_64

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
             This is the *original* / standard Ruby Language Interpreter
      'ree'  represents Ruby Enterprise Edition
      'rbx'  represents Rubinius

Additional Dependencies:
# For update-system:
Always update your system first!

# For rvm:
Install: bash curl git patch

# For ruby:
Install: osx-gcc-installer libksba openssl libreadline git zlib1g libyaml libsqlite3     sqlite3 libxml2 libxslt autoconf libc6 libgdbm ncurses automake libtool bison pkg-config

# For jruby:
Install: openjdk ant

有人可以帮我解决这个问题吗?提前致谢。

【问题讨论】:

    标签: ruby macos command-line installation jekyll


    【解决方案1】:

    除了(或取而代之,取决于工具)Xcode,您还需要命令行工具,它可以从 Xcode 的首选项窗格中安装。 Xcode 可以在 App Store 中找到,应该是免费的或非常便宜的。

    顺便说一句,我强烈建议你不要乱用系统自带的 ruby​​;安装 rvm 以获得完全隔离的 ruby​​ 版本(您可以选择您喜欢的版本),您可以在其中安装所有 gem。

    安装 rvm 后,只需执行以下操作:

    rvm install 1.8.7
    rvm use 1.8.7
    gem install jekyll
    

    更新

    如果你需要gcc来编译某个版本的Ruby,你应该install homebrew,然后使用这个命令安装gcc:

    brew tap homebrew/dupes && brew install apple-gcc42
    

    否则尝试安装 Ruby 1.9.3,AFAIK 应该可以与 LLVM/GCC 一起使用(我现在不在 Mac 上,无法检查)。

    【讨论】:

    • 谢谢,我现在正在下载 XCode 并观看了有关 RVM 的教程。这看起来像我正在寻找的解决方案。我为系统自己的 Ruby 更新了 gems 重要吗?我知道你说过我不应该惹它,但我在不知不觉中就这么做了。
    • @DanRosenthal 我不知道 OSX 对 Ruby 和它自己的 gems 做了什么,我想这可能有问题。如果您能够从备份中恢复 gem 目录,这可能是个好主意,但如果您不觉得有任何损坏,请不要做任何事情。
    【解决方案2】:

    我过去曾这样做过,但我个人并不记得所有细节。您可以尝试在超级用户上查看此相关帖子(解决方案 #2:“找不到头文件”):https://superuser.com/questions/154292/ruby-rubygems-why-do-i-always-get-error-messages-when-trying-to-install-gems

    【讨论】:

      【解决方案3】:

      如果您尚未安装 Xcode,请按照所述安装 (https://developer.apple.com/xcode/)。 另外您需要命令行工具。

      打开 Xcode。转至Preferences &gt; Downloads &gt; Install Command Line Tools

      【讨论】: