苹果电脑无法安装Jekyll Gem

3

我尝试了各种方法来安装jekyll gem。我卸载/重新安装了rbenv,安装了ruby 2.6.1,并将其设置为全局,运行了 xcode-select --install 大约1000次,运行了xcode-select --switch /Library/Developer/CommandLineToolsgem update --system等各种stackoverflow的解决方法。但是这些方法都没有奏效。每次都出现下面这个熟悉的错误信息:

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

    current directory: /usr/local/lib/ruby/gems/2.6.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
/usr/local/opt/ruby/bin/ruby -I 
/usr/local/Cellar/ruby/2.6.1/lib/ruby/2.6.0 -r ./siteconf20190302-90413-16ok71q.rb extconf.rb
creating Makefile

current directory: /usr/local/lib/ruby/gems/2.6.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR=" clean

current directory: /usr/local/lib/ruby/gems/2.6.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR="
compiling ruby_http_parser.c
In file included from ruby_http_parser.c:1:
In file included from /usr/local/Cellar/ruby/2.6.1/include/ruby-2.6.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.6.1/include/ruby-2.6.0/ruby/ruby.h:29:
/usr/local/Cellar/ruby/2.6.1/include/ruby-2.6.0/ruby/defines.h:123:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
make: *** [ruby_http_parser.o] Error 1

make failed, exit code 2

Gem files will remain installed in /usr/local/lib/ruby/gems/2.6.0/gems/http_parser.rb-0.6.0 for inspection.
Results logged to 
/usr/local/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0/http_parser.rb-0.6.0/gem_make.out

编辑:

我正在使用MacOS 10.14,这是我的gem环境:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.2
  - RUBY VERSION: 2.6.1 (2019-01-30 patchlevel 33) [x86_64-darwin18]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.6.0
  - USER INSTALLATION DIRECTORY: /Users/<username>/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/2.6.0/bin
  - SPEC CACHE DIRECTORY: /Users/<username>/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: 
    /usr/local/Cellar/ruby/2.6.1/etc
  - RUBYGEMS PLATFORMS:
        - ruby
        - x86_64-darwin-18
  - GEM PATHS:
        - /usr/local/lib/ruby/gems/2.6.0
        - /Users/<username>/.gem/ruby/2.6.0
        - /usr/local/Cellar/ruby/2.6.1/lib/ruby/gems/2.6.0
  - GEM CONFIGURATION:
        - :update_sources => true
        - :verbose => true
        - :backtrace => false
        - :bulk_threshold => 1000
  - REMOTE SOURCES:
        - https://rubygems.org/
  - SHELL PATH:
        - /usr/local/opt/ruby/bin
        - /bin
        - /Users/<username>/.rbenv/shims
        - /Users/<username>/.rbenv/bin
        - /Library/Frameworks/Python.framework/Versions/3.6/bin
        - /usr/local/bin
        - /usr/bin
        - /bin
        - /usr/sbin
        - /sbin
        - /opt/X11/bin
        - /usr/local/share/dotnet
        - /usr/local/go/bin
        - /Users/<username>/.rbenv/bin
        - /Users/<username>/.rbenv/shims
        - /Users/<username>/.rbenv/shims
        - /Users/<username>/.rbenv/bin
        - /Library/Frameworks/Python.framework/Versions/3.6/bin
        - /usr/local/bin
        - /usr/bin
        - /bin
        - /usr/sbin
        - /sbin
        - /usr/local/go/bin
        - /usr/local/share/dotnet
        - /opt/X11/bin
        - /Users/<username>/.rbenv/bin
        - /Users/<username>/.rbenv/shims
        - /bin

我不确定为什么我的$PATH中会有这么多重复项,但可能是由于我的bash_profile文件。


请返回 gem env 命令的输出。 - lacostenycoder
你的 MacOS 版本是什么? - lacostenycoder
我在编辑中添加了它们。 - genghiskhan
1个回答

3

看起来你的PATH设置加载的是系统ruby而不是rbenv的ruby。

尝试从你的.bash_profile中删除此行,因为你不想使用系统ruby而是RBENV版本的ruby。

/usr/local/opt/ruby/bin

如果这样做不起作用,我不确定为什么您的路径中会有这么多重复项,可能是由于尝试使用RBENV多次而导致的。建议您首先重新安装RBENV。您需要执行以下步骤卸载RBENV:uninstall RBENV,然后重新安装。
grep rbenv ~/.bashrc ~/.bash_profile ~/.zshrc /etc/profile /etc/profile.d/*

移除任何文件中与 RBENV 相关的行。

移除 rbenv。

rm -rf ~/.rbenv 

如果你使用了Homebrew安装rbenv,那么

brew uninstall rbenv

运行brew doctor,查看是否有其他问题报告。

关闭所有正在运行的终端,然后打开一个新的终端。然后再次检查gem env,您将看到一个更干净的状态,没有与RBENV相关的内容,只有您的系统Ruby。

或者如果您喜欢,您可以先尝试使用RVM,如需了解详细信息,请参见https://rvm.io/rvm/install

之后您可能需要重新启动终端,然后进入您的Middleman项目文件夹并运行

bundle install

你为什么建议使用RVM而不是rbenv?我不能只尝试编辑我的PATH以指向rbenv的ruby吗? - genghiskhan
1
我将 PATH 中的 /usr/local/opt/ruby 更改为 ~/.rbenv/versions/2.6.1,然后 gem install 现在成功运行了!我将把您的答案标记为正确,但您可能需要进行编辑。 - genghiskhan
1
@genghiskhan,我更新了我的答案,很高兴它指引你找到了正确的方向并且让它工作了。但是你可能不想在你的配置文件中特别选择版本,让RBENV自己选择吧。 - lacostenycoder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接