本文翻译自:Error while installing json gem 'mkmf.rb can't find header files for ruby'
For context, it on a remote server which has a firewall. 对于上下文,它位于具有防火墙的远程服务器上。 I'm setting up my environment through a proxy. 我正在通过代理设置环境。 I have ruby 1.8.7
. 我有ruby 1.8.7
。 When I try to gem install.. 当我尝试gem install ..
sudo gem install --http-proxy <host address>:<port> json
I get the following error: 我收到以下错误:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/json-1.8.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
Since I was unsure what the problem is, I googled and found these 由于我不确定是什么问题,因此我搜索并找到了这些
gem install: Failed to build gem native extension (can't find header files) - the instructions here seem to be specific to the gem being installed. gem install:无法构建gem本机扩展(找不到头文件) -此处的说明似乎特定于要安装的gem。
How to install json gem - Failed to build gem native extension This seems to be slightly different error. 如何安装json gem-无法构建gem本机扩展名这似乎是稍有不同的错误。
Any hints? 有什么提示吗? Thanks! 谢谢!
#1楼
参考:https://stackoom.com/question/1ogoT/安装json-gem时出错-mkmf-rb找不到ruby的头文件
#2楼
Modern era update, as stated by mimoralea : 如mimoralea所述,现代更新:
In case that you are using ruby 2.0 or 2.2 (thanks @patrick-davey). 如果您使用的是ruby 2.0或2.2(感谢@ patrick-davey)。
sudo apt-get install ruby-dev sudo apt-get install ruby2.0-dev sudo apt-get install ruby2.2-dev sudo apt-get install ruby2.3-dev
or, generic way: 或者,通用方式:
sudo apt-get install ruby`ruby -e 'puts RUBY_VERSION[/\\d+\\.\\d+/]'`-dev
The first link you've posted is exactly your case: there is no ruby development environment installed. 您发布的第一个链接正是您的情况:没有安装ruby开发环境。 Development env is needed to compile ruby extensions, which are mostly written in C
. 需要开发环境来编译ruby扩展,这些扩展大部分是用C
编写的。 Proxy has nothing to do with the problem: everything is downloaded fine, just compilation fails. 代理与问题无关:一切都下载良好,只是编译失败。
I would suggest you to install ruby-dev
( ruby-devel
for rpm-based distros) package onto you target machine. 我建议您将ruby-dev
(基于rpm的发行版的ruby-devel
)软件包安装到目标计算机上。 gcc
package might be needed as well. 也可能需要gcc
软件包。
Try: 尝试:
$ sudo apt-get install ruby-dev
Or, for Redhat distro: 或者,对于Redhat发行版:
$ sudo yum install ruby-devel
Or, for [open]SuSE: 或者,对于[open] SuSE:
$ sudo zypper install ruby-devel
#3楼
如果您使用SUSE
sudo yast2 -i ruby-devel
#4楼
In case that you are using ruby 2.0 or 2.2 (thanks @patrick-davey) or 2.3 (thanks @juanitofatas). 如果您使用的是ruby 2.0或2.2(感谢@ patrick-davey)或2.3(感谢@juanitofatas)。
sudo apt-get install ruby-dev
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
And you get the pattern here... 你在这里得到了模式...
#5楼
在Fedora 21及更高版本中,您只需打开终端并以root身份安装Ruby Development文件。
dnf install ruby-devel
#6楼
I also encountered this problem because I install Ruby on Ubuntu via brightbox , and I thought ruby-dev is the trunk of ruby. 我也遇到了这个问题,因为我通过Brightbox在Ubuntu上安装了Ruby ,并且我认为ruby-dev是ruby的主干。 So I did not install. 所以我没有安装。 Install ruby2.3-dev fixes it: 安装ruby2.3-dev可以修复它:
sudo apt-get install ruby2.3-dev