安装json Ruby gem时出错

时间:2017-04-12 02:42:00

标签: ruby-on-rails json ruby rubygems

我正在运行gem install json -v '1.8.1'但我收到此错误..

gem install json -v '1.8.1'
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20170412-72871-wada1h.rb extconf.rb
creating Makefile

current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:47: error: too few arguments provided to function-like macro invocation
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
                                              ^
/Users/johnwilliamson/.rvm/rubies/ruby-2.4.1/include/ruby-2.4.0/ruby/intern.h:795:9: note: macro 'rb_str_new' defined here
#define rb_str_new(str, len) RB_GNUC_EXTENSION_BLOCK(   \
        ^
In file included from generator.c:1:
./../fbuffer/fbuffer.h:175:11: warning: incompatible pointer to integer conversion initializing 'VALUE' (aka 'unsigned long') with an expression of type 'VALUE (const char *, long)' (aka 'unsigned long (const char *, long)') [-Wint-conversion]
    VALUE result = rb_str_new(FBUFFER_PAIR(fb));
          ^        ~~~~~~~~~~
generator.c:840:25: error: use of undeclared identifier 'rb_cFixnum'
    } else if (klass == rb_cFixnum) {
                        ^
generator.c:842:25: error: use of undeclared identifier 'rb_cBignum'
    } else if (klass == rb_cBignum) {
                        ^
1 warning and 3 errors generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/gems/json-1.8.1 for inspection.
Results logged to /Users/johnwilliamson/.rvm/gems/ruby-2.4.1/extensions/x86_64-darwin-16/2.4.0/json-1.8.1/gem_make.out

当我只运行gem install json时,它会安装好我的版本2但是我正在尝试安装此https://github.com/peatio/peatio并且它特别想要该版本。

还有其他想法吗?

3 个答案:

答案 0 :(得分:0)

由于您不在正确的目录中,因此会出现此问题。请先转到rails目录文件夹,然后运行以下命令:

rails@rails:~/rails_project/btc$ gem install json -v '1.8.1'

然后它的工作正常。

答案 1 :(得分:0)

这似乎是json 1.8.1 gem的常见问题。如果要明确声明json,则可以使用其他版本的json,但在某些情况下,json 1.8.1是级联的依赖项。例如,您可能会看到类似

ngOnInit() {
      // STEP 1
      this.loadUserPefsService.getUserRolePefs(roleId).subscribe(
          (returnedListPefs) => {
            this.permittedPefs = returnedListPefs;
           // STEP 2
           this.myMethod(1);  // check this line
          },
          error => {
            console.log(error);
          });
}

在这种情况下,您只需要将顶级gem(在这种情况下为rails)更改为其他版本。 4.2.6有效。

答案 2 :(得分:0)

查找和更新在JSON gem中提取的gem应该可以工作。但是,对我有用的另一件事是更新正在安装的JSON版本。

bundle update json

之所以可行,是因为它将JSON更新到了与较新的Rubies兼容的版本1.8.6。