关于ruby on rails:无法安装带有gem的json

Can't install json with gem

我在终端(OSX 10.6.6)中尝试了以下命令并最终出错。 有谁知道如何解决这个问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
sudo gem install json

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

        /usr/local/bin/ruby extconf.rb
checking for ruby/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.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/bin/ruby
/usr/local/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:452:in `
try_cpp'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:834:in `block in have_header'

    from /usr/local/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `
block (2 levels) in postpone'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open'

    from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `
open'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'

    from /usr/local/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:833:in `
have_header'
    from extconf.rb:17:in `'



Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/json-1.5.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/json-1.5.1/ext/json/ext/generator/gem_make.out

您应该能够通过运行来安装必要的工具:

1
> xcode-select --install

您收到此错误的原因是因为json gem包含需要在您的计算机上运行才能运行的C / C ++扩展。

只是安装XCode无法修复它,您需要专门安装XCode命令行工具。 它是一个编译器/链接器工具链,包括C / C ++编译器,make等。

可以选择在XCode GUI的菜单中安装它们,有关详细信息,请参阅此主题:

Xcode 4.4及更高版本安装命令行工具


您需要安装XCode。 它可以在AppStore上找到

如果安装了XCode并且您仍然收到此错误,也许您应该尝试使用rvm