无法在 Ubuntu 20.04 上为 Ruby 版本 2.5.3 安装 json 版本 1.8.2 gem

Unable to install json version 1.8.2 gem for Ruby version 2.5.3 on Ubuntu 20.04

我正在尝试 运行 rails 服务器,当我 运行 bundle install 命令时,出现以下错误:

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

当我 运行 推荐的命令 gem 安装 gem install json -v '1.8.3' --source 'https://rubygems.org/' 时,我在构建本机扩展时出错

Building native extensions. This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/json-1.8.3/ext/json/ext/generator
/home/user/.rvm/rubies/ruby-2.5.3/bin/ruby -I /home/user/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0 -r ./siteconf20210822-103903-1kc2ys9.rb extconf.rb
creating Makefile

current directory: /home/user/.rvm/gems/ruby-2.5.3/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /home/user/.rvm/gems/ruby-2.5.3/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); did you mean ‘mFixnum’?
  861 |     } else if (klass == rb_cFixnum) {
      |                         ^~~~~~~~~~
      |                         mFixnum
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); did you mean ‘mBignum’?
  863 |     } else if (klass == rb_cBignum) {
      |                         ^~~~~~~~~~
      |                         mBignum
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’
make: *** [Makefile:242: generator.o] Error 1

make failed, exit code 2

我不知道如何解决这个问题,任何帮助将不胜感激

您正在尝试安装 2015 年的 very old version of gem json

这个 gem 依赖于某些 ruby headers,例如 Bignum,后者已在 ruby 的最新版本中删除。

尝试安装此 gem 的更新版本,例如:

gem install json -v '2.5.1' --source 'https://rubygems.org/'

或者,您可以尝试 downgrade your ruby version to 2.3.0 并尝试在 1.8.3 上安装 json 版本。

关注 然后 运行 bundle install 或者只是 运行 bundle update json.