2017-02-20 117 views
5

[版本信息]错误安装JSON 1.8.3红宝石2.4

红宝石2.4.0p0(2016年12月24日修订版57164)[x86_64的Linux的] /GEM 2.0.3/ 视窗10

我跑bundle install它告诉我跑gem install json -v '1.8.3'

我这样做,并得到了失败打造宝石原生扩展错误

Building native extensions. This could take a while... 

ERROR: Error installing json: 
     ERROR: Failed to build gem native extension. 
    /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 files will remain installed in /home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3 for inspection. 
Results logged to /home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out 

我检查了几个文件。 我安装的devkit和JSON 1.8.5,但我的项目一直是“安装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 

/home/ec2-user/.rvm/gems/ruby-2.4.0/gems/json-1.8.3/ext/json/ext/generator/gem_make.out包含:

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 
+0

第一个问题是为什么你需要JSON宝石? Ruby具有内置的JSON支持。其次,为什么要使用旧版本? Ruby 2.4.0改变了许多可能需要使用最新版本的gem的内部。如果你对这个特定版本的依赖性很强,你可能需要使用Ruby 2.3.x或者它可以编译的东西,直到你可以删除这个限制。 – tadman

+0

@tadman我需要JSON版本1.8.3,因为putty需要我。如果我运行'bundle install',putty命令我设置JSON 1.8.3。我安装了其他版本(2.0.3和2.0。2),但它一直说“安装JSON 1.8.3”。其实我是初学者,只是遵循了我的指导原则,所以我在处理问题时不灵活。 –

回答

7

我遇到了同样的问题,最近还有,试试,看看是否有您正在使用的任何宝石的新版本取决于json 1.8.3。这是因为Ruby 2.4统一了Fixnum and Bignum into Integer。如果您能够升级到json 1.8.5或更高版本,它应该有助于解决您的问题。

您也可以尝试和更新您正在使用的宝石,并尽量放松版本的限制(我发现这个有很多的项目工作,但不是全部),像这样:

gem 'json', '>= 1.8' 
+0

我试图安装新版本的宝石,但它给了我这个错误。 –

+0

未定义的方法'source_paths'为#

+0

@김혜진这是一个新问题,所以至少你得到了一个地方。通常这是与Rubygems进行交互并期望成为旧版本的问题。 – tadman

0

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

0

我面临同样的问题。可行的办法是,我们应该首先从宝石

"gem uninstall json" 

取出JSON,然后 安装

"sudo bundle install" 

不要忘了加sudo。没有sudo它将无法安装。

+1

'不要以root身份运行Bundler。 Bundler可以询问sudo是否需要,并且 以root用户身份安装捆绑软件将会破坏此应用程序,用于此计算机上的所有非root用户 用户.' – Magicode

2

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

+0

这是唯一适用于我的解决方案。谢谢。 – guero64

0

我执行的以下步骤:在插入的Gemfile上述命令(宝石“JSON”,“> = 1.8”),并与运行束错误的事件安装我被实现捆绑更新和安装的依赖关系。