Miantian
Miantian

Reputation: 1075

Can't install a gem on CentOS 8

Use root user installed rubygems.

# yum install rubygems -y

When check ruby's version, got

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

Gem's version:

# gem -v
2.7.6.3

When install a gem, got

# 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

Should I install a high version ruby? It's the default one on the system.


update

I installed ruby-devel

# yum install ruby-devel.x86_64

Run install fluent-plugin-kinesis gem again

# 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

For other gems works well.

Upvotes: 0

Views: 1276

Answers (1)

Sumak
Sumak

Reputation: 1051

Take a look at the docs or this answer.

Install Ruby >= 2.4 on your local environment. In addition, install ruby-dev package via Package Manager to build native extension gems.

I believe in CentOS ruby-dev equivalent is ruby-devel. You can confirm it by running yum search ruby-dev

You'll find 2 packages, one i686 and another x86_64. You can find which one you need by running lscpu | grep Arch.

Then simply download the package, and rerun gem install

Upvotes: 2

Related Questions