使用ruby 2.4安装json 1.8.3时出错

使用ruby 2.4安装json 1.8.3时出错,ruby,Ruby,[版本资料] ruby 2.4.0p0(2016-12-24修订版57164)[x86_64-linux] /创业板2.0.3/ 视窗10 我运行了bundle安装,它告诉我运行gem安装json-v'1.8.3' 我这样做了,并得到了一个无法构建gem本机扩展的错误 我查了好几份文件。 我安装了Devkit和json 1.8.5,但我的项目保留了“install json 1.8.3”的消息 我怎样才能解决这个问题 /home/ec2 user/.rvm/gems/ruby-2.4.0/gem

[版本资料]

ruby 2.4.0p0(2016-12-24修订版57164)[x86_64-linux] /创业板2.0.3/ 视窗10

我运行了
bundle安装
,它告诉我运行
gem安装json-v'1.8.3'

我这样做了,并得到了一个无法构建gem本机扩展的错误

我查了好几份文件。 我安装了Devkit和json 1.8.5,但我的项目保留了“install json 1.8.3”的消息 我怎样才能解决这个问题

/home/ec2 user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3
包含:

../
./
data/
diagrams/
ext/
java/
lib/
tests/
tools/
install.rb*
.gitignore
.travis.yml
CHANGES
COPYING
COPYING-json-jruby
GPL
Gemfile
README-json-jruby.markdown
README.rdoc
Rakefile
user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
/home/ec2-user/.rvm/rubies/ruby-2.4.0/bin/ruby extconf.rb
creating Makefile

make
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" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
make: *** [generator.o] Error 1
/home/ec2 user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem\u make.out包含:

../
./
data/
diagrams/
ext/
java/
lib/
tests/
tools/
install.rb*
.gitignore
.travis.yml
CHANGES
COPYING
COPYING-json-jruby
GPL
Gemfile
README-json-jruby.markdown
README.rdoc
Rakefile
user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
/home/ec2-user/.rvm/rubies/ruby-2.4.0/bin/ruby extconf.rb
creating Makefile

make
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" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-constant-logical-operand" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-parentheses-equality" [enabled by default]
cc1: warning: unrecognized command line option "-Wno-tautological-compare" [enabled by default]
make: *** [generator.o] Error 1

我最近也遇到了同样的问题,试着看看是否有一个更新版本的gem依赖于json 1.8.3。这是因为Ruby 2.4实现了统一。如果您能够升级到或更高版本,它将有助于解决您的问题

您还可以尝试更新正在使用的gem,并尝试放宽版本限制(我发现这适用于许多项目,但不是所有项目),如下所示:


我强制安装了json 1.8.5,并更改了Gemfile.lock中的条目,现在似乎可以正常工作。

我也遇到了同样的问题。可行的解决方案是,我们应该首先从gem中删除json

"gem uninstall json"
然后 安装

别忘了添加sudo。如果没有sudo,它将无法安装


尝试删除Gemfile.lock并再次运行bundle命令。它应该使用不同版本的json(即1.8.6),没有问题。

我执行了以下步骤:在gemfile(gem'json','>=1.8')中插入上述命令,在运行bundle安装时发生错误,我实现了bundle更新和安装依赖项。

在gemfile.lock中

json (~>1.8.3)
然后做

bundle update

需要将Gemfile.lock中以“json”开头的行更改为以下行

json(~>1.8.3)
什么对我有用


第一个问题是为什么需要JSON gem?Ruby内置了JSON支持。其次,为什么要使用旧版本?Ruby 2.4.0改变了许多可能需要使用该gem最新版本的内部构件。如果您在这个特定版本上有一个硬依赖,您可能需要使用Ruby 2.3.x或它可以编译的东西,直到您可以删除这个限制。@tadman我需要JSON版本1.8.3,因为putty需要我。如果我运行
bundle install
,putty命令我设置JSON 1.8.3。我安装了其他版本(2.0.3和2.0.2),但它一直说“安装JSON 1.8.3”。。事实上,我是一个初学者,只是遵循我的指导原则,所以我在处理问题时不够灵活。@TadmanRuby2.6.5也有同样的问题。在我的例子中,JSON是一个req。动态支持的宝石。安装v1.8.5解决了这个问题(v1.8.4不存在)。我试图安装更新版本的gem,但它给了我这个错误#@김혜진 这是一个新问题,所以至少你有进展了。通常这是一个与Rubygems交互的问题,希望是一个较旧的版本。我降级了ruby版本,这个JSON错误消失了。谢谢你的帮助!在我的情况下,只需更新到最新版本(即2.5.1)
,不要以root用户身份运行Bundler。Bundler可以在需要时请求sudo,并且将您的bundle安装为root将破坏此计算机上所有非root用户的应用程序。
这应该是可以接受的答案。如果您没有明确要求,您不应该被迫使用
gem'json','>=1.8'
污染您的gem文件。当您删除Gemfile.lock时,您允许bundler构建一个新的依赖关系树,并尝试解决不兼容问题。如果您只想更新该gem,但将其余gem锁定到
Gemfile.lock
中的版本,只需运行
bundle update json
。这对我有用。
bundle update
   1.)  gem install json_pure
   2.)    rvm list
          ruby-2.1.5 [ x86_64 ]
       =* ruby-2.7.1 [ x86_64 ]
   3.) rvm use 2.1.5
   4.) bundle install