当我尝试 sudo gem install json 时出现以下错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/761521/
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
When I try sudo gem install json I get the following error
提问by
I need to install the JSON gem to start my app but I get the error below whenever I try to install the json gem. Can anyone help me out. I'm using rails 2.2.2 and gems 1.3.1.
我需要安装 JSON gem 才能启动我的应用程序,但是每当我尝试安装 json gem 时都会收到以下错误。谁能帮我吗。我正在使用 rails 2.2.2 和 gems 1.3.1。
Arions-macbook-pro:.ssh arion$ sudo gem install json
Password:
Sorry, try again.
Password:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install json
can't find header files for ruby.
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.1.4 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.1.4/ext/json/ext/parser/gem_make.out
回答by Javid Jamae
With Mavericks, you can solve this problem by installing the Xcode Command Line Tools from the command line like this:
使用 Mavericks,您可以通过从命令行安装 Xcode 命令行工具来解决这个问题,如下所示:
xcode-select --install
xcode-select --install
Update: Don't forget to accept the license agreement after you install or update:
更新:安装或更新后不要忘记接受许可协议:
sudo xcodebuild -license
sudo xcodebuild -license
回答by Diego Freniche
If you have this problem:
如果你有这个问题:
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
and you are using a Mac with OS X (tested with 10.8.1 Mountain Lion), you need to download Xcode from the Mac App Store (or from developer.apple.com if you have a dev account - it's free BTW and you can download a DMG installer)
并且您使用的是装有 OS X 的 Mac(使用 10.8.1 Mountain Lion 测试),您需要从 Mac App Store(或从 developer.apple.com,如果您有开发帐户 - 它是免费的 顺便说一句,您可以下载 DMG 安装程序)
The latest Xcode versions (I'm using Xcode 4.4.1) does NOT include command line tools. Now you need to install this additional package inside Xcode. Once done, your problem is fixed.
最新的 Xcode 版本(我使用的是 Xcode 4.4.1)不包括命令行工具。现在你需要在 Xcode 中安装这个额外的包。完成后,您的问题就解决了。
To do that, open Xcode, go to Preferences > Downloads > Components. Install "Command Line Tools". You're done. Now you can install the json Ruby gem.
为此,请打开 Xcode,转到首选项 > 下载 > 组件。安装“命令行工具”。你完成了。现在您可以安装 json Ruby gem。


回答by neomorphic
You are missing the ruby development headers. To install these on an OS like ubuntu you should use:
您缺少 ruby 开发标头。要将这些安装在像 ubuntu 这样的操作系统上,您应该使用:
aptitude install ruby1.8-dev
回答by neomorphic
The ruby headers don't come installed with the base ruby install with Mac OS X. These can been found on Mac OS X Install Disc 2 by installing the XCode Tools.
ruby 头文件没有随 Mac OS X 的基本 ruby 安装一起安装。这些可以通过安装 XCode 工具在 Mac OS X 安装光盘 2 上找到。
Once installed, all was well!
一旦安装,一切都很好!
UPDATEAs of at least OS X 10.7.3 this is no longer a problem, it "just works"
更新至少从 OS X 10.7.3 开始,这不再是问题,它“可以正常工作”
MacBook-Pro:tmp$ sudo gem install json
Password:
Building native extensions. This could take a while...
Successfully installed json-1.6.5
1 gem installed
Installing ri documentation for json-1.6.5...
Installing RDoc documentation for json-1.6.5...
MacBook-Pro:tmp$ uname -a
回答by p01nd3xt3r
Installing Xcode command line tools... should fix this issue.
安装 Xcode 命令行工具...应该可以解决这个问题。
回答by Janco
A simple google searchreveals this:
一个简单的谷歌搜索揭示了这一点:
If you get the can't find header files for ruby error message when trying to build an extension or a gem, it means that Ruby cannot locate its header files.
如果您在尝试构建扩展或 gem 时收到找不到 ruby 头文件的错误消息,则意味着 Ruby 无法找到其头文件。
Header files are not delivered by default with Mac OS X, you need to install the Xcode Tools package after the installation. You can find it in the Optional Installs / Xcode Tools directory on the Leopard DVD.
Mac OS X默认不提供头文件,安装后需要安装Xcode Tools包。您可以在 Leopard DVD 的 Optional Installs / Xcode Tools 目录中找到它。
回答by adu
It turns out certain gems require some ruby header files to install properly. These header files do notship with Lion (OSX 10.7).
事实证明,某些 gem 需要一些 ruby 头文件才能正确安装。这些头文件不随 Lion (OSX 10.7) 一起提供。
It also turns out Xcode 4 (latest release) also does notinstall these header files. I tried this.
事实证明,Xcode 4(最新版本)也没有安装这些头文件。我试过这个。
Solution -Assuming you are on Mac OS X (you appear to be based on the terminal output). To get it working I installed gcc with some developer toolsfrom the following page
解决方案 -假设您使用的是 Mac OS X(您似乎是基于终端输出)。为了让它工作,我使用以下页面中的一些开发人员工具安装了 gcc
- Visit https://github.com/kennethreitz/osx-gcc-installer
- Scroll down to the README and download the appropriate package (for OSX 10.7 or 10.6)
- Open the
.pkgfile and run the installer.
- 访问https://github.com/kennethreitz/osx-gcc-installer
- 向下滚动到自述文件并下载相应的包(适用于 OSX 10.7 或 10.6)
- 打开
.pkg文件并运行安装程序。
You should be able to install the gems now, either with gem installor bundle install.
您现在应该可以使用gem install或安装 gems bundle install。
OverheadIf you are worried about the other junk this comes with, here is a summary.
开销如果您担心随之而来的其他垃圾,这里是一个总结。
gcc- usefulmake- usefulclang- useful for ObjectiveC- Developer CLI Tools (purge, etc) - useful?
- DevSDK (headers, etc) - what you need
gcc- 有用make- 有用clang- 对 ObjectiveC 有用- 开发人员 CLI 工具(清除等)- 有用吗?
- DevSDK(头文件等)——你需要什么
回答by Alan David Garcia
If you use homebrew, run brew doctor. You might find out that the required gcc libraries for compilation are outdated and/or missing.
如果您使用自制软件,请运行brew doctor. 您可能会发现编译所需的 gcc 库已过时和/或丢失。
Warning: No compiler found in /usr/bin!
Warning: Your Xcode (4.2) is outdated
checking for gcc... /Developer/usr/bin/llvm-gcc
checking whether the C compiler works... no
configure: error: in `/private/tmp/freexl-apNF/freexl-1.0.0d':
configure: error: C compiler cannot create executables
For Lion and Mountain Lion users, Apple now provides an official Command Line Tools for Xcode package that you can install without needing to install Xcode itself! You can download it from Apple's developer site https://developer.apple.com/downloads/index.action. If you still need gcc-4.2, and you use Homebrew, you can install it using the apple-gcc42 package from homebrew/dupes.
对于 Lion 和 Mountain Lion 用户,Apple 现在提供了官方的 Xcode 命令行工具包,您无需安装 Xcode 即可安装!您可以从 Apple 的开发者网站https://developer.apple.com/downloads/index.action下载它。如果你仍然需要 gcc-4.2,并且你使用 Homebrew,你可以使用 homebrew/dupes 中的 apple-gcc42 包安装它。
回答by Hymanie Chan
Here is my solution:
这是我的解决方案:
rvm gem install json -v=xxx
My setup:
我的设置:
OSX Lion ruby-1.9.3 rvm gcc-4.2 #=> honestly haven't seen that it's been used
回答by Anar Jafarov
I had the same problem.
我有同样的问题。
Here is my adventures (hope it will be useful):
这是我的冒险经历(希望有用):
To fix it I've done many manipulations :-)
为了修复它,我做了很多操作:-)
I'm using Fedora Core. I've fixed it this way:
我正在使用 Fedora 核心。我是这样修复的:
I've installed rails-devel:
我已经安装了 rails-devel:
sudo yum install rails-devel
须藤 yum 安装 rails-devel
tried again:
再次尝试:
sudo gem install rails
须藤宝石安装导轨
but I've got another problem:
但我还有另一个问题:
Building native extensions. This could take a while... ERROR: Error installing rails: ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb creating Makefilemake gcc -I. -I/usr/lib/ruby/1.8/i386-linux -I/usr/lib/ruby/1.8/i386-linux -I. -D_FILE_OFFSET_BITS=64 -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -fno-strict-aliasing -fPIC -O3 -Wall -c parser.c make: gcc: Command not found
构建原生扩展。这可能需要一段时间... 错误:安装导轨时出错:错误:无法构建 gem 本机扩展。
/usr/bin/ruby extconf.rb creating Makefile制作 gcc -I。-I/usr/lib/ruby/1.8/i386-linux -I/usr/lib/ruby/1.8/i386-linux -I. -D_FILE_OFFSET_BITS=64 -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous -unwind-tables -fno-strict-aliasing -fPIC -O3 -Wall -c parser.c make: gcc: 命令未找到
So I've installed GCC:
所以我已经安装了 GCC:
sudo yum install gcc
须藤 yum 安装 gcc
tried again:
再次尝试:
sudo gem install rails
须藤宝石安装导轨
Now I've got another problem ))) :
现在我有另一个问题 ))) :
Installing ri documentation for json-1.6.3... ERROR: While generating documentation for json-1.6.3 ... MESSAGE: no such file to load -- irb/slex ... RDOC args: --ri --op /usr/lib/ruby/gems/1.8/doc/json-1.6.3/ri --title JSON implemention for Ruby --main README.rdoc ext/json/ext ext lib README.rdoc --title json-1.6.3 Documentation --quiet
为 json-1.6.3 安装 ri 文档...错误:为 json-1.6.3 生成文档时...消息:没有要加载的文件 -- irb/slex ... RDOC 参数:--ri --op /usr/lib/ruby/gems/1.8/doc/json-1.6.3/ri --title Ruby JSON 实现 --main README.rdoc ext/json/ext ext lib README.rdoc --title json-1.6。 3 文档 --quiet
So installed ruby-irb:
所以安装了ruby-irb:
sudo yum install ruby-irb
须藤 yum 安装 ruby-irb
tried again:
再次尝试:
sudo gem install rails
Successfully installed rails-3.1.3
须藤宝石安装导轨
成功安装 rails-3.1.3
That's all )))
就这样 )))

