Docker for Mac - mkmf.rb 找不到 ruby​​ 的头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46377667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:53:15  来源:igfitidea点击:

Docker for Mac - mkmf.rb can't find header files for ruby

rubydocker

提问by Torben

I updated XCode on my Mac and since then when starting Docker using docker-sync-stack startI get this error message:

我在 Mac 上更新了 XCode,从那时起使用 Docker 启动时docker-sync-stack start我收到以下错误消息:

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

I tried installing ruby with this: brew install rbenv ruby-buildbut this does not change anything.

我尝试用这个安装 ruby​​:brew install rbenv ruby-build但这不会改变任何东西。

Does anybody know how I can fix it?

有人知道我该如何解决吗?

Thanks!

谢谢!

回答by ryanpcmcquen

None of the other solutions worked for me, here's what I ran to resolve the issue on Mac OS 10.14.x:

其他解决方案都不适合我,这是我在 Mac OS 10.14.x 上解决问题的方法:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

回答by joki

For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with

对于macOS 10.14 上的 Xcode 11,即使在安装 Xcode 并安装命令行工具并接受许可证后,也会发生这种情况

sudo xcode-select --install
sudo xcodebuild -license accept

The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running

问题是 Xcode 11 提供了 macOS 10.15 SDK,其中包括 ruby​​2.6 的头文件,但不包括 macOS 10.14 的 ruby​​2.3。您可以通过运行来验证这是您的问题

ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

which on macOS 10.14 with Xcode 11 prints the non-existentpath

在 macOS 10.14 和 Xcode 11 上打印不存在的路径

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:

但是,Xcode 11 在/Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. 没有必要通过安装其他答案中建议的旧头文件来污染系统目录。相反,通过选择该 SDK,将找到适当的 ruby​​2.3 标头:

sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'

This should now correctly print

这现在应该正确打印

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

Likewise, gem installshould work while that SDK is selected.

同样,gem install应在选择该 SDK 时工作。

To switch back to using the current Xcode 11 SDK, use

要切换回使用当前的 Xcode 11 SDK,请使用

sudo xcode-select --switch /Applications/Xcode.app

回答by tadman

When upgrading XCode you need to install the Command-Line Tools and additionally accept the terms and conditions:

升级 XCode 时,您需要安装命令行工具并另外接受条款和条件:

sudo xcode-select --install

Then:

然后:

sudo xcodebuild -license

回答by bdorfman

As of Xcode 11, it seems like the ruby development headers are no longer included, so you will need to manually install them outside of Xcode Command Line Tools.

从 Xcode 11 开始,似乎不再包含 ruby​​ 开发头文件,因此您需要在 Xcode 命令行工具之外手动安装它们。

E.g. for me using rbenv i did

例如,对我来说,我使用了 rbenv

rbenv install 2.6.4
rbenv global 2.6.4
eval "$(rbenv init -)"

Then ran bundle install and everything worked as expected.

然后运行 ​​bundle install ,一切都按预期工作。

回答by Sergey Tykhonov

For Xcode 11 I fixed this by also installing of /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkgpackage.

对于 Xcode 11,我还通过安装/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg包解决了这个问题。

回答by SudoPlz

Single line command fix:

单行命令修复:

On OSX Mojave I ran the following command:

在 OSX Mojave 上,我运行了以下命令:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

and it fixed the issue.

它解决了这个问题。

回答by fnordl

As @bdorfmansaid in his comment, the Ruby headers are no longer included as of Xcode 11 build but they seem to try to make a new build for this as soon as possible (?): https://discuss.circleci.com/t/xcode-11-gm-seed-2-released/32505/12.

正如@bdorfman在他的评论中所说,从 Xcode 11 版本开始,Ruby 头文件不再包含在内,但他们似乎试图尽快为此构建一个新版本(?):https: //discuss.circleci.com/ t/xcode-11-gm-seed-2-released/32505/12

What worked for me was to use rbenvlike @bdorfman said:

对我有用的是rbenv像@bdorfman 所说的那样使用:

rbenv install 2.6.4
rbenv global 2.6.4
eval "$(rbenv init -)"

But with the extra step of adding docker-syncto your new ruby version. Since after you change the ruby version (for example)

但是添加docker-sync到您的新 ruby​​ 版本的额外步骤。因为在您更改 ruby​​ 版本之后(例如)

$ ruby -v
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin18]

And then running gem list:

然后运行 ​​gem list:

$ gem list
bigdecimal (default: 1.4.1)
bundler (default: 1.17.2)
cmath (default: 1.0.0)
csv (default: 3.0.9)
date (default: 2.0.0)
dbm (default: 1.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
etc (default: 1.0.1)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
logger (default: 1.3.0)
matrix (default: 0.1.0)
minitest (5.11.3)
mutex_m (default: 0.1.0)
net-telnet (0.2.0)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
power_assert (1.1.3)
prime (default: 0.1.0)
psych (default: 3.1.0)
rake (12.3.2)
rdoc (default: 6.1.2)
rexml (default: 3.1.9)
rss (default: 0.2.7)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
stringio (default: 0.0.2)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.2.9)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
webrick (default: 1.4.2)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

(does not contains docker-sync)

(不包含 docker-sync)

If you run the gem install for docker-sync you will use the docker-sync for your rbenv managed ruby.

如果您为 docker-sync 运行 gem install,您将为 rbenv 管理的 ruby​​ 使用 docker-sync。

$ gem install docker-sync

$ gem install docker-sync

回答by Duan Nguyen

I had the same problem while installing fastlane. The tadman's answer is correct, but the command lines don't work for me with Xcode 10.2.1 (I'm not sure with other versions). You need to open Xcode, then open Preferences, select Locations and choose Command Line Tools. In my case, Command Line Tools field is empty.

我在安装 fastlane 时遇到了同样的问题。tadman 的回答是正确的,但命令行不适用于 Xcode 10.2.1(我不确定其他版本)。您需要打开 Xcode,然后打开 Preferences,选择 Locations 并选择 Command Line Tools。就我而言,命令行工具字段为空。

回答by Dmytro Hutsuliak

If you want to get a deeper insight into the issue:

如果你想更深入地了解这个问题:

Mac OS X 10.14 has stopped placing the include libraries in their usual location, /usr/include, keeping them only inside the XCode directory.

To confirm that this is the problem, simply run ls /usr/include. If the result comes out empty, its really this problem.

Apple ships a “legacy installer” for you to be able to install the headers in the “old location”. To fix the problem just run this:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Mac OS X 10.14 已停止将包含库放置在其通常的位置 /usr/include 中,仅将它们保留在 XCode 目录中。

要确认这是问题所在,只需运行ls /usr/include. 如果结果出来是空的,那就真的是这个问题了。

Apple 提供了一个“旧版安装程序”,您可以在“旧位置”安装标头。要解决此问题,只需运行以下命令:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/

https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/

回答by LordKiz

Running open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkgin the terminal opens the package installation wizard. After properly installing was I able to proceed.

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg在终端中运行会打开包安装向导。正确安装后,我就可以继续了。

MacOS 10.4.4

macOS 10.4.4