Ruby-on-rails 无法使用 Windows 在 rails 中安装 JSON gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7780756/
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-03 02:10:07  来源:igfitidea点击:

Cannot install JSON gem in rails using windows

ruby-on-railsrubygem

提问by Ray A.

I am doing a bundle install and all of the gems work fine except JSON when it get to the JSON gem I receive this error.

我正在执行捆绑安装,并且当它到达 JSON gem 时,除了 JSON 之外的所有 gem 都可以正常工作,我收到此错误。

Installing json (1.6.1) with native extensions c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:55
    2:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::E
    xtensionBuildError)

            c:/Ruby192/bin/ruby.exe extconf.rb
    checking for re.h... *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

Any idea on what could be causing this error?

关于可能导致此错误的任何想法?

回答by knut

You are working with Windows, so the RubyInstaller Development Kit may help you: http://rubyinstaller.org/add-ons/devkit/

您正在使用 Windows,因此 RubyInstaller 开发工具包可能会帮助您:http://rubyinstaller.org/add-ons/devkit/

The devkit installs a C-compiler (and some other stuff) to compile C-written parts.

devkit 安装了一个 C 编译器(和其他一些东西)来编译 C 编写的部分。

Install it and try again to install the gem - perhaps with option --platform=ruby.

安装它并再次尝试安装 gem - 也许有选项--platform=ruby

Details can be found at https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

详细信息可以在https://github.com/oneclick/rubyinstaller/wiki/Development-Kit找到

回答by WarHog

That's because this gem using a piece of code written on C. For working properly you need c compiler installed on your machine. As a way, try to use json_purewritten on pure Ruby

那是因为这个 gem 使用了一段用 C 编写的代码。为了正常工作,你需要在你的机器上安装 c 编译器。作为一种方式,尝试使用纯 Ruby 编写的json_pure

回答by junkle

I'm not an expert in ROR, but the JSON installation issue which I got while installing Redmine was resolved by doing the following:

我不是 ROR 方面的专家,但是我在安装 Redmine 时遇到的 JSON 安装问题是通过执行以下操作解决的:

  • Create a make.bat at D:\LANGS\MinGW\bin
  • Keep this directory in the PATH
  • Edit the above make.bat and add a line, D:\LANGS\MinGW\msys\1.0\bin\make.exe
  • 在 D:\LANGS\MinGW\bin 创建一个 make.bat
  • 将此目录保留在 PATH 中
  • 编辑上面的make.bat,添加一行,D:\LANGS\MinGW\msys\1.0\bin\make.exe

What I realized is, mingw32-make.exe never worked, but 'D:\LANGS\MinGW\msys\1.0\bin\make.exe' worked.

我意识到, mingw32-make.exe 从来没有工作过,但 'D:\LANGS\MinGW\msys\1.0\bin\make.exe' 工作。

Note: My MinGW installation is under D:\LANGS\ . Please make the changes accordingly in your specific installation.

注意:我的 MinGW 安装在 D:\LANGS\ 下。请在您的特定安装中进行相应的更改。

回答by Andy Rossignol

Yes, install the development kit. Also, You will need to run a few command lines to install it (not just simply download and run).

是的,安装开发工具包。此外,您需要运行一些命令行来安装它(不仅仅是下载和运行)。

Download it, run it to extract it somewhere (permanent). Then cd to it, run ruby dk.rb init and ruby dk.rb install to bind it to ruby installations in your path.

下载它,运行它以将其解压缩到某处(永久)。然后 cd 到它,运行 ruby​​ dk.rb init 和 ruby​​ dk.rb install 将它绑定到路径中的 ruby​​ 安装。

A guide for that is here:

一个指南在这里:

https://github.com/oneclick/rubyinstaller/wiki/Development-Kit

https://github.com/oneclick/rubyinstaller/wiki/Development-Kit