Error on installing gem Nokogiri-1.8.4 - ruby

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?

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 :)

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

Related

How to set up ruby on Docker - getting nokogiri error

My Doc Dockerfile has FROM Ubuntu:18.04
I want to use ruby so i did
gem install bundler
However when I try to
bundle
I get an error with nokogiri
Installing nokogiri 1.10.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20190414-288-1mfprtc.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out
An error occurred while installing nokogiri (1.10.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.10.2' --source 'http://rubygems.org/'` succeeds before bundling.
You have a dependency called nokogiri that has external dependency, usually it's libxml and libxslt.
All you need to do is apt get install libxml2-dev libxslt1-dev
Here's a working example of a Ruby Dockerfile
FROM ruby:2.6.2
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y libxml2-dev libxslt1-dev
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY Gemfile* /usr/src/app/
RUN bundle install -j3
ADD . /usr/src/app
ENTRYPOINT ["bundle", "exec"]
CMD ["rails", "server"]

rmagick install error ubunutu 16.04 ruby 2.4.0p0

I tried to install rmagick using these commands, but it doesn't work.
sudo apt-get install imagemagick
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
sudo gem install rmagick
It ended up with the following error.
Building native extensions.
This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/rmagick-2.16.0/ext/RMagick /usr/bin/ruby2.3
-r ./siteconf20170603-20826-3to4j3.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.3.0/gems/rmagick-2.16.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rmagick-2.16.0/gem_make.out
You need to install also the ruby-dev package. That is why the ruby.h is not found when compiling a native extension.
Use the following command to install it.
sudo apt-get install ruby-dev
Basing on the package description, that will install the ruby2.3-dev package. That was the package it installed on my Ubuntu 16.04.
Package: ruby-dev
State: not installed
Multi-Arch: same
Version: 2:2.3.0+1bbox1~xenial1
Priority: optional
Section: devel
Maintainer: Antonio Terceiro
Architecture: amd64
Uncompressed Size: 20.5 k
Depends: ruby2.3-dev
Provided by: ruby1.8-dev (1:1.8.7.375-1bbox1~xenial2)
Description: Header files for compiling extension modules for Ruby (default version) Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in perl). It is simple, straight-forward, and extensible. This package contains the header files and the mkmf library, necessary to make extension library for Ruby. It is also required to build many gems. This package is a dependency package, which depends on Debian's default Ruby version (currently v2.3).
I then installed Ruby 2.4, so now that package doesn't result installed on my computer.

Vagrant Failed to Build Gem Native Extension

I'm running Vagrant 1.8.1 on OSX 10.11.3 and I'm trying to install a plugin. While attempting to install I get the following the error:
vagrant plugin install vagrant-libvirt
............
An error occurred while installing ruby-libvirt (0.6.0), and Bundler cannot continue.
Make sure that `gem install ruby-libvirt -v '0.6.0'` succeeds before bundling.
.........
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
ruby-livirt 0.6.0 has already been installed:
# gem list | grep ruby-libvirt
# ruby-libvirt (0.6.0)
Can I bypass this error since the gem is already installed?
I had the same error while installing vagrant plugin install vagrant-libvirt it turned out that I was missing some libraries.
After installing below libraries on Ubuntu 16.04 I was able successfully install vagrant-libvirt plugin with vagrant plugin install command.
bridge-utils
build-dep
dnsmasq-base
ebtables
libguestfs-tools
libvirt-bin
libvirt-dev
libxml2-dev
libxslt-dev
qemu
qemu-kvm
ruby-dev
ruby-libvirt
virt-top
virtinst zlib1g-dev
Depends on your Linux distribution you might look at this link to find matching libraries.

Failed to build gem native extension

I want to install in my Fedora 12 based planet lab nodes one OMF RC:
It requres ruby 1.9.3. So, I installed git, then ruby-devel then rvm. With rvm i installed:
rvm install 1.9.3
After all this when i want to install:
gem install omf_rc --pre --no-ri --no-rdoc
It gives me the following error:
Building native extensions. This could take a while...
ERROR: Error installing omf_rc:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.h... * extconf.rb failed *
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers
Please let me know how to solve this. Thanks
seems you need to install libxml, try:
sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
Also it needs the following installation:
sudo yum install -y git make gcc-c++
and
sudo yum groupinstall development-tools development-libs

How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?

I'm installing the Ruby Nokogiri gem and finding the error below.
How to diagnose this and solve it?
# gem install nokogiri
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
...
/opt/ruby/1.9.3-p194/bin/ruby extconf.rb
checking for libxml/parser.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.
...
/opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do':
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /opt/ruby/1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
...
To diagnose and solve, here's what worked for me.
To find out what failed, go to your ruby gems directory.
For example:
$ cd <MY RUBY DIRECTORY>/lib/ruby/gems/2.0.0/gems
If you don't know your gem directory, try this:
$ echo $GEM_HOME
/opt/gems/2.0.0
$ cd /opt/gems/2.0.0/gems
What version of nokogiri am I installing?
$ ls -ladg nokogiri-*
nokogiri-1.5.5
Go to the installer directory:
$ cd nokogiri-1.5.5/ext/nokogiri
Try installing manually:
$ ruby extconf.rb
Result:
checking for libxml/parser.h... *** extconf.rb failed ***
...
I'm using Ubuntu so I search for any similar packages:
$ aptitude search libxml
Results:
p libxml2 - GNOME XML library
p libxml2-dev - Development files for the GNOME XML library
...
I believe that libxml2 will work fine.
$ apt-get install libxml2
Ruby native gems often need the *-dev packages for headers so install them:
$ apt-get install libxml2-dev
Now do I have the parser file?
$ find / | grep libxml/parser.h
Yes, the result shows the parser:
/usr/include/libxml2/libxml/parser.h
Now try installing again, this time providing the libxml2 path:
$ gem install nokogiri -- --with-xml2-dir=/usr/include/libxml2
It still fails, so read the mkmf error log:
$ more mkmf.log
The error log shows what failed and has these lines that look promising:
package configuration for libxslt is not found
Is there a package for it?
$ aptitude search libxslt
Results:
v libxslt-dev
i libxslt-ruby
...
Install the dev package:
$ apt-get install libxslt-dev
Now try installing again, and also put xslt on the path:
$ gem install nokogiri -- \
--with-xml2-dir=/usr/include/libxml2 \
--with-xslt-dir=/usr/include/libxslt
Success!
Installing Nokogiri Website
'Installing Nokogiri' is a website dedicated to installing Nokogiri on the major platforms - Here is an excerpt about Installing Nokogiri on Ubuntu:
Because Nokogiri needs to be compiled and dynamically linked against
both libxml2 and libxslt, it has gained a reputation for being
complicated to install.
As of Nokogiri 1.6, libxml2 and libxslt source code is bundled with
Nokogiri, and compiled at gem-install-time. The instructions in this
document should work for all versions 1.6.4 and later.
Ubuntu / Debian
Installation should Just Work™ on Ubuntu and Debian using Nokogiri’s
vendored libxml2 and libxslt:
gem install nokogiri
[...]
Using Your System Libraries
If, instead of Nokogiri’s vendored libraries, you’d like to use your
system’s libxml2, libxslt and related libraries, please first
understand that you may be asking Nokogiri to work with an unsupported
version of libxml2.
sudo apt-get install pkg-config
gem install nokogiri -- --use-system-libraries
FYI - I am using Nokogiri 1.6.6.2 and it didn't 'just work'. I got it going with the --use-system-libraries.
Mac OS X
The website's advice also covers OS X - this worked for me:
gem update --system
xcode-select --install
gem install nokogiri
Conclusion
If you have a Nokogiri problem on any platform you should check out the website.
On CentOS here is what I needed to do:
gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
You are probably missing zlib headers which are required for -lz flag in order to compile the sources correctly. Install on Linux by:
sudo apt-get install libz-dev
For missing libiconv, try installing libiconv-hook-dev package which has header files of libiconv-hook, e.g.
sudo apt-get install libiconv-hook1 libiconv-hook-dev
On OS X, try installing development tools via: xcode-select --install.
If there is still problem, check mkmf.log file for more specific details about your error.
On Ubuntu, try the following dependency fix combo:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
The 'could not create Makefile' error you're seeing could also be because you haven't agreed to the Xcode license (you have to agree to it after each time you update Xcode). Running sudo xcodebuild -license accept should eliminate this error for you and allow you to then run gem install nokogiri successfully.

Resources