0

I try to bundle install --gemfile=Gemfile, but error occurs as:

An error occurred while installing nokogiri (1.7.2), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.7.2' --source 'http://rubygems.org/' succeeds before bundling.

So I try install nokogiri, then refused:

ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.

It seems nokogiri was locked. I wonder how to install specific version(1.7.2) of nokogiri.

My OS is Amazon Linux AMI release 2017.09, and I have installed

mysql-devel sqlite-devel libcurl-devel ruby24 ruby24-devel zlib-devel gcc libxslt-devel libxml2-devel gcc-c++ make curl

Ruby version is 2.4 and bundler at version 1.17.3. Detailed error info is:

current directory: /usr/local/share/ruby/gems/2.4/gems/nokogiri-1.7.2/ext/nokogiri
/usr/bin/ruby2.4 -r ./siteconf20190305-30890-gjsryi.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:

Building Nokogiri with a packaged version of libxml2-2.9.4
with the following patches applied:
    - 0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch
    - 0002-Fix-XPointer-paths-beginning-with-range-to.patch
    - 0003-Disallow-namespace-nodes-in-XPointer-ranges.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows: 
gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
TeWu
  • 5,928
  • 2
  • 22
  • 36
yfqin
  • 41
  • 3
  • This is a common problem in Ruby environments, nokogiri uses compiles native C code when installing you will need the tools needed to make C applications, what operational system are you using? Is there any more information on the error, it usually gives a bit more (unable to locate headers for example) – Danilo Cabello Mar 05 '19 at 12:17
  • I think, this will help you https://stackoverflow.com/questions/16028028/nokogiri-will-not-install-error-failed-to-build-gem-native-extension?answertab=votes#tab-top – gururuby Mar 05 '19 at 12:30
  • If you are on Ubuntu, as a quick and dirty fix, that might, or might not work, you can try installing common missing libraries, with command: `sudo apt-get install build-essential patch libgmp-dev libxml2-dev libxslt1-dev zlib1g-dev liblzma-dev` – TeWu Mar 05 '19 at 12:39
  • 1
    `gem install nokogiri -- --use-system-libraries` works. Thanks for your kindly help! – yfqin Mar 05 '19 at 12:48
  • hi @yfqin try to always that is possible to use the system-libraries. They get all security updates and you update it with the linux distribution package manager. – VP. Mar 05 '19 at 14:11

0 Answers0