本文介绍了安装 json gem 时出错“mkmf.rb 找不到 ruby​​ 的头文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于上下文,它位于具有防火墙的远程服务器上.我正在通过代理设置我的环境.我有 ruby 1.8.7.当我尝试安装 gem 时..

sudo gem install --http-proxy :json

我收到以下错误:

构建原生扩展.这可能需要一段时间...错误:安装 json 时出错:错误:无法构建 gem 本机扩展./usr/bin/ruby extconf.rbmkmf.rb 在/usr/lib/ruby/ruby.h 找不到 ruby​​ 的头文件Gem 文件将保留安装在/usr/lib64/ruby/gems/1.8/gems/json-1.8.1 中以供检查.结果记录到/usr/lib64/ruby/gems/1.8/gems/json-1.8.1/ext/json/ext/generator/gem_make.out

由于我不确定问题是什么,我用谷歌搜索并找到了这些

有什么提示吗?谢谢!

解决方案

现代更新,如 由 mimoralea 陈述:

如果您使用的是 ruby​​ 2.0 或 2.2(感谢@patrick-davey).

sudo apt-get install ruby​​2.0-dev须藤 apt-get 安装 ruby​​2.2-dev须藤 apt-get 安装 ruby​​2.3-dev

或者,通用方式:

sudo apt-get install ruby​​-dev

sudo apt-get install ruby​​`ruby -e 'puts RUBY_VERSION[/d+.d+/]'`-dev

您发布的第一个链接正是您的情况:没有安装 ruby​​ 开发环境.编译 ruby​​ 扩展需要开发环境,这些扩展大多是用 C 编写的.代理与问题无关:一切下载正常,只是编译失败.

我建议您在目标机器上安装 ruby-dev(ruby-devel 用于基于 rpm 的发行版)包.

可能还需要

gcc 包.

试试:

$ sudo apt-get install ruby​​-dev

或者,对于 Redhat 发行版:

$ sudo yum install ruby​​-devel

或者,对于[open]SuSE:

$ sudo zypper install ruby​​-devel

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. When I try to 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

Any hints? Thanks!

解决方案

Modern era update, as stated by mimoralea:

or, generic way:


The first link you’ve posted is exactly your case: there is no ruby development environment installed. Development env is needed to compile ruby extensions, which are mostly written in 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.

gcc package might be needed as well.

Try:

$ sudo apt-get install ruby-dev

Or, for Redhat distro:

$ sudo yum install ruby-devel

Or, for [open]SuSE:

$ sudo zypper install ruby-devel

这篇关于安装 json gem 时出错“mkmf.rb 找不到 ruby​​ 的头文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 18:16