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

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

正在安装红矿。 我试过了,

bundle install --without development test postgresql sqlite

,但出错。

Gem::Ext::BuildError: 错误:无法构建 gem 本机扩展。

current directory:
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
/usr/local/bin/ruby -r ./siteconf20161228-21055-1dxe9y9.rb extconf.rb
creating Makefile

current directory:
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
/usr/local/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: error: ‘rb_cFixnum’ undeclared (first use in this
function)
generator.c:861: error: (Each undeclared identifier is reported only
once
generator.c:861: error: for each function it appears in.)
generator.c:863: error: ‘rb_cBignum’ undeclared (first use in this
function)
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"
make: *** [generator.o] error 1

make failed, exit code 2

Gem files will remain installed in
/usr/local/lib/ruby/gems/2.4.0/gems/json-1.8.3 for inspection.
Results logged to
/usr/local/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,但我无法解决。

你介意读一下这个问题吗?

第一个运行

gem install bundler

它安装了较新的捆绑器并解决了本机扩展依赖关系

然后 运行

bundle install 

它应该可以解决您的问题

Ruby 2.4 非常新。事实上,它仅在 3 天前发布。

由于 Ruby 2.4 中有几个重要的内部更改,很可能许多 gem(和 Redmine 本身)还不兼容此版本的 Ruby .

从您的错误消息来看,JSON gem 似乎确实需要调整才能处理 Ruby 2.4 中有关整数的一些更改。

您现在应该使用旧版本的 Ruby,例如Ruby 2.3.3。正如您在 http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Ruby-interpreter 上看到的那样,Redmine 需要特定的 Ruby 版本,具体取决于 Redmine 的版本。

我现在遇到了同样的问题。 要解决此问题,请使用 gem install 手动安装最新版本的 bundlerrmagick,并使用 gem updatebundle update 更新所有其他软件包。 这解决了 json 1.8.3ruby 2.4.

的依赖问题

不过我运行在后记中有些问题较多。 它看起来像 ruby 2.4 对数字的解释做了一些改变,这意味着它不再与 rail 4.x 兼容 。 更新 rails 及其依赖项似乎还不可能,因为 redmine 需要 protected_attributes 这取决于 activemodel (< 5.0, >= 4.0.1)rails 5.x 取决于 activemodel 5.x.

如果更新破坏了向后兼容性,尤其是对于编程语言来说,这总是不好的:(

json gem 似乎在较新的 ruby 版本 (2.4+) 中存在错误,makandracards 的 answer 提出了一个简单易行的方法解决方案。

答案是关于更新 json gem 的版本以解决错误并成功安装 gem。因此,它使用 --conservative 选项更新 json gem。

bundle update json --conservative