无法在Mac OS X 10.8.4上安装json 1.8 gem

3

我正在尝试在第二台计算机上安装我的Rails应用程序。但是当我运行bundle install时,我遇到了有关json gem的错误:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby extconf.rb 
/Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby: invalid option -D  (-h will show valid options) (RuntimeError)


Gem files will remain installed in /Users/feuerball/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0 for inspection.
Results logged to /Users/feuerball/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/ext/json/ext/generator/gem_make.out

An error occurred while installing json (1.8.0), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.0'` succeeds before bundling.

这台电脑运行的是Mac OS X 10.8.4,安装了Xcode 4.6.3和最新的命令行工具。

我使用rvm安装了最新的ruby:

$ rvm -v

rvm 1.21.2 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

$ ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]
$ gem -v
2.0.3

当我尝试使用gem install json安装json gem时,我几乎得到相同的错误:

Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    /Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby extconf.rb
/Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby: invalid option -D  (-h will show valid options) (RuntimeError)


Gem files will remain installed in /Users/feuerball/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0 for inspection.
Results logged to /Users/feuerball/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/ext/json/ext/generator/gem_make.out

尝试使用sudo安装没有改变任何内容。 我卸载并重新安装了homebrew、rvm、ruby和命令行工具,但仍然无济于事。 更新 /Users/feuerball/.rvm/gems/ruby-2.0.0-p195/gems/json-1.8.0/ext/json/ext/generato‌​r/gem_make.out的内容:
/Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby extconf.rb
/Users/feuerball/.rvm/rubies/ruby-2.0.0-p195/bin/ruby: invalid option -D  (-h will show valid options) (RuntimeError)

GCC版本:

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

更新2

我进行了一次全新的OS X、Xcode、命令行工具、Homebrew、rvm和Ruby安装。Ruby现在是补丁级别247,但该问题仍然存在。真是浪费时间...如果重要的话:rvm与ruby一起安装了json 1.7.7

更新3

似乎我的机器无法安装所有本地扩展。gem install bcrypt-ruby会出现相同的错误信息。


由于它只包含2行,我将其插入到原始帖子中。 - stevecross
现在它已经在原帖中了。 - stevecross
你在rvm中将ruby-2.0.0-p195设置为默认的ruby了吗? - Remear
是的,我认为是这样的,因为我直接与rvm一起安装了它。 - stevecross
没有帮助。似乎我的机器无法构建本地宝石。现在我尝试安装bcrypt-ruby时出现相同的错误。 - stevecross
显示剩余3条评论
3个回答

6
问题在于我的主文件夹位于一个名称中包含空格的单独卷中。由于这个空格,名称的第二部分被解释为选项。这个卷的名字类似于“My Data”,因此我得到了消息“无效选项-D”。
我只是重新命名了这个卷,现在一切都可以安装了。

我也遇到了同样的问题...谢谢! - Travis Swientek
1
同样的问题。基本上,捆绑包无法处理路径名称中的空格,导致错误的参数解析。真是太遗憾了。 - kureikain

1

这似乎发生在Json版本1.8.0和1.8.1(Ruby 2.2.3)...我能够升级到1.8.2和1.8.3而没有问题...指定这些版本

gem 'json', '~> 1.8.2'

在我的束中解决了这个问题。

这并没有解决问题,因为它不是由json gem引起的。 - stevecross

-1

正如我所写的那样,gem install json也不起作用。同时,sudo也没有改变任何东西。 - stevecross
3
请注意,永远不要在 rvm 中使用sudo。 - Remear

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接