简体   繁体   English

无法使用gem安装json

[英]Can't install json with gem

I have tried following command in terminal (OSX 10.6.6) and end up with an error. 我尝试在终端(OSX 10.6.6)中执行以下命令,并最终出现错误。 Does anyone know how to solve this? 有谁知道如何解决这个问题?

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

The reason you're getting this error is because the json gem includes C/C++ extensions that need to be compiled on your machine before they can run. 您收到此错误的原因是因为json gem包含C / C ++扩展,这些扩展需要在您的计算机上进行编译才能运行。

Just installing XCode won't fix it, you need to specifically install the XCode Command Line Tools. 仅仅安装XCode并不能解决问题,您需要专门安装XCode命令行工具。 It's a compiler/linker toolchain including C/C++ compilers, make, etc. 这是一个编译器/链接器工具链,包括C / C ++编译器,make等。

There's an option to install them within a menu inside the XCode GUI, see this thread for details: 有一个选项可以将它们安装在XCode GUI的菜单中,有关详细信息,请参见以下线程:

Xcode 4.4 and later install Command Line Tools Xcode 4.4及更高版本安装命令行工具

您应该能够通过运行以下命令安装必要的工具:

> xcode-select --install

You will need to install XCode. 您将需要安装XCode。 It is available on the AppStore 它可以在AppStore上获得

If XCode is installed and you are still getting this error, maybe you should try using rvm 如果已安装XCode,但仍然出现此错误,也许您应该尝试使用rvm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM