在Ubuntu上安装带有ruby 2.4.0的json 1.8.3时出错

时间:2017-03-10 08:06:07

标签: ruby-on-rails json ruby ubuntu

我正在尝试在我的本地计算机上运行一个开源Web应用程序(Ubuntu 15.10)。当我运行bundle命令时,我得到了这个

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/yesh/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
/home/yesh/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170310-4319-tlc92v.rb
extconf.rb
creating Makefile

current directory:
/home/yesh/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
/home/yesh/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c: In function ‘generate_json’:
generator.c:861:25: error: ‘rb_cFixnum’ undeclared (first use in this function)
     } else if (klass == rb_cFixnum) {
                         ^
generator.c:861:25: note: each undeclared identifier is reported only once for
each function it appears in
generator.c:863:25: error: ‘rb_cBignum’ undeclared (first use in this function)
     } else if (klass == rb_cBignum) {
                         ^
generator.c: At top level:
cc1: warning: unrecognized command line option ‘-Wno-self-assign’
cc1: warning: unrecognized command line option ‘-Wno-constant-logical-operand’
cc1: warning: unrecognized command line option ‘-Wno-parentheses-equality’
cc1: warning: unrecognized command line option ‘-Wno-tautological-compare’
Makefile:241: recipe for target 'generator.o' failed
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/home/yesh/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3 for
inspection.
Results logged to
/home/yesh/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/json-1.8.3/gem_make.out

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

所以我尝试了gem install json -v '1.8.3'但又得到了与上面相同的错误消息。请帮忙解决这个问题。

2 个答案:

答案 0 :(得分:6)

我认为你可以解决你的问题:

sudo apt-get install libgmp3-dev

如果上面的命令没有解决你的系统,你可以尝试安装这个命令:

sudo apt-get install libgmp-dev

您可以参考json-1.8.3 Gem::Ext::BuildError

因为你的ruby版本是2.4.0。ruby版本与json 1.8.3不兼容。您可以尝试在Gemfile中添加此行:

gem 'json', github: 'flori/json', branch: 'v1.8'

答案 1 :(得分:0)

看起来你的Ruby版本与Project的Ruby版本不同。 JSON仅支持从2.0.0版开始的Ruby中的Integer统一。以及 - 也许一些列出的宝石依赖于json (~> 1.8)。在Gemfile中注释掉这个gem并运行bundle install或降级Ruby。 Read more about this issue