2

OS: AMI 2018.03.0 (HVM)
Ruby version: 2.3.7p456 (2018-03-28 revision 63024) [x86_64-linux-gnu] - installed using yum install ruby23

gem install nokogiri throws:

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

current directory: /home/ec2-user/.gem/ruby/2.3/gems/nokogiri- 
1.8.4/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20180801-6218-101te4s.rb extconf.rb
mkmf.rb can't find header files for ruby at 
/usr/share/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /home/ec2- 
user/.gem/ruby/2.3/gems/nokogiri-1.8.4 for inspection.
Results logged to /home/ec2-user/.gem/ruby/2.3/extensions/x86_64- 
linux/2.3/nokogiri-1.8.4/gem_make.out

what am i missing here?

shivam_v
  • 71
  • 11
  • 1
    Don't try to use the system Ruby for development. I recommend installing rvm or rbenv for managing your development rubies. – Leo Aug 01 '18 at 08:58
  • Using rvm/rben makes sense for dev environment to manage multiple versions. But on a server, you shouldn't need multiple rb versions. Useful to consider - but perhaps misplaced advice. ;) – zaTricky Aug 01 '18 at 14:50

2 Answers2

3

From the error output, it would seem it can't find the development dependencies for Ruby, which Nokogiri is trying to use in order to build the gem natively.

You can run yum -y install gcc ruby-devel rubygems to make certain the dependencies are installed.

Basing my answer somewhat from https://stackoverflow.com/a/4502672/1129980

Update

Tested this now on a new EC2 instance:

yum install -y ruby23-devel gcc libxml2 libxml2-devel libxslt libxslt-devel patch
gem install nokogiri --no-ri --no-rdoc

That works :)

Casper
  • 33,403
  • 4
  • 84
  • 79
jc1arke
  • 116
  • 6
0

Try running the below mentioned commands

sudo yum -y install ruby-dev ( or ruby-devel)
sudo yum -y install libgmp-dev libgmpxx4ldbl ruby-dev ruby2.3-dev
Rohan
  • 2,681
  • 1
  • 12
  • 18