【问题标题】:Can't install a gem on CentOS 8无法在 CentOS 8 上安装 gem
【发布时间】:2021-08-25 09:27:20
【问题描述】:

使用 root 用户安装的 ruby​​gems。

# yum install rubygems -y

查看 ruby​​ 的版本时,得到

# ruby -v
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]

Gem 的版本:

# gem -v
2.7.6.3

安装 gem 时,得到

# gem install fluent-plugin-kinesis
Building native extensions. This could take a while...
ERROR:  Error installing fluent-plugin-kinesis:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/share/gems/gems/msgpack-1.4.2/ext/msgpack
/usr/bin/ruby -r ./siteconf20210825-20925-17fyw57.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /usr/local/share/gems/gems/msgpack-1.4.2 for inspection.
Results logged to /usr/local/lib64/gems/ruby/msgpack-1.4.2/gem_make.out

我应该安装高版本的 ruby​​ 吗?这是系统上的默认设置。


更新

我安装了ruby-devel

# yum install ruby-devel.x86_64

再次运行 install fluent-plugin-kinesis gem

# gem install fluent-plugin-kinesis
Building native extensions. This could take a while...
ERROR:  Error installing fluent-plugin-kinesis:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/share/gems/gems/msgpack-1.4.2/ext/msgpack
/usr/bin/ruby -r ./siteconf20210826-11878-18i9eps.rb extconf.rb
checking for ruby/st.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib64
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/$(RUBY_BASE_NAME)
/usr/share/ruby/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/share/ruby/mkmf.rb:590:in `try_cpp'
    from /usr/share/ruby/mkmf.rb:1098:in `block in have_header'
    from /usr/share/ruby/mkmf.rb:948:in `block in checking_for'
    from /usr/share/ruby/mkmf.rb:350:in `block (2 levels) in postpone'
    from /usr/share/ruby/mkmf.rb:320:in `open'
    from /usr/share/ruby/mkmf.rb:350:in `block in postpone'
    from /usr/share/ruby/mkmf.rb:320:in `open'
    from /usr/share/ruby/mkmf.rb:346:in `postpone'
    from /usr/share/ruby/mkmf.rb:947:in `checking_for'
    from /usr/share/ruby/mkmf.rb:1097:in `have_header'
    from extconf.rb:3:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/lib64/gems/ruby/msgpack-1.4.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/share/gems/gems/msgpack-1.4.2 for inspection.
Results logged to /usr/local/lib64/gems/ruby/msgpack-1.4.2/gem_make.out

对于其他宝石效果很好。

【问题讨论】:

    标签: ruby rubygems


    【解决方案1】:

    看看docs 或这个answer

    在您的本地环境中安装 Ruby >= 2.4。此外,通过包管理器安装 ruby​​-dev 包以构建原生扩展 gem。

    我相信 CentOS 中的ruby-dev 相当于ruby-devel。你可以通过运行yum search ruby-dev来确认它

    您会找到 2 个包,一个 i686 和另一个 x86_64。你可以通过运行lscpu | grep Arch找到你需要的。

    然后只需下载包,然后重新运行gem install

    【讨论】:

    • 我在问题中添加了update。我按照你的指南做了,但仍然无法安装 gem。在 Before Installation 我没有找到 gem 的一些设置。但是我通过td-agent-gem install fluent-plugin-kinesis安装了插件。
    • 糟糕的是,我希望这能奏效!也许我们可以看看mkmf.log,如果您想了解它失败的原因,请尝试找出是否缺少标头/库。
    • 我查看了mkmf.log文件,内容和stdout日志一样。但我可以用另一种方式安装特殊的 gem。还是谢谢大家。
    猜你喜欢
    • 2020-11-04
    • 2022-01-08
    • 2020-06-25
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2014-06-11
    • 1970-01-01
    • 2015-02-02
    相关资源
    最近更新 更多