Error while installing json gem 'mkmf.rb can't find header files for ruby'

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

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 : 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!

回答1:

Modern era update, as stated by mimoralea:

In case that you are using ruby 2.0 or 2.2 (thanks @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. 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 


回答2:

In case that you are using ruby 2.0 or 2.2 (thanks @patrick-davey) or 2.3 (thanks @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...



回答3:

I also encountered this problem because I install Ruby on Ubuntu via brightbox, and I thought ruby-dev is the trunk of ruby. So I did not install. Install ruby2.3-dev fixes it:

sudo apt-get install ruby2.3-dev 


回答4:

in case you use SUSE

sudo yast2 -i ruby-devel 


回答5:

I had a similar problem using cygwin to run the following command:

$ gem install rerun 

I solved it by installing the following cygwin packages:

  • ruby-devel
  • libffi-devel
  • gcc-core
  • gcc-g++
  • make
  • automake1.15


回答6:

In Fedora 21 and up, you simply open a terminal and install the Ruby Development files as root.

dnf install ruby-devel 


回答7:

For those who are getting this on Mac OS X you may need to run the following command to install the XCode command-line tools, even if you already have XCode installed:

sudo xcode-select --install 

Also you must agree the terms and conditions of XCode by running the following command:

sudo xcodebuild -license 


回答8:

You may need to install gcc after install ruby-devel



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!