问题描述
对于上下文,它位于具有防火墙的远程服务器上.我正在通过代理设置我的环境.我有 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
由于我不确定问题是什么,我用谷歌搜索并找到了这些
gem 安装: 无法构建 gem 本机扩展(找不到头文件) - 此处的说明似乎特定于正在安装的 gem.
如何安装jsongem - 无法构建 gem 本机扩展这似乎是稍微不同的错误.
有什么提示吗?谢谢!
现代更新,如 由 mimoralea 陈述:
如果您使用的是 ruby 2.0 或 2.2(感谢@patrick-davey).
sudo apt-get install ruby2.0-dev须藤 apt-get 安装 ruby2.2-dev须藤 apt-get 安装 ruby2.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
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.
How to install json gem - Failed to build gem native extension This seems to be slightly different error.
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 的头文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!