1

When attempting to install Nokogiri via bundler/capistrano I am receiving the error:

An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue

Digging deeper I can see >> libxml2 version 2.6.21 or later is required!

The error message also says Make sure that gem install nokogiri -v '1.6.5' succeeds before bundling.

Well, as you can see this is not a problem:

vagrant@vagrant:~$ gem install nokogiri -v '1.6.5'
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.5
1 gem installed

Sadly, even when this test is passed, the cap deploy still fails with the same error.

An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue

I have I have ensured the latest version of libxml2 is installed on my virtualbox. I even removed my project directory, and rebooted the server:

$ vagrant ssh
$ sudo apt-get update
$ sudo apt-get upgrade libxml2
$ sudo rm -rf /var/www/rails-devise-capistrano/
$ sudo reboot

I have also tried added this to deploy.rb

set :bundle_env_variables, { nokogiri_use_system_libraries: 1 }

Here is the bundler error

/home/vagrant/.rbenv/versions/2.2.2/bin/ruby -r ./siteconf20150704-1327-1yf3b95.rb extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** 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}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/vagrant/.rbenv/versions/2.2.2/bin/$(RUBY_BASE_NAME)
        --help
        --clean
        --use-system-libraries=true
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-xml2-dir
        --without-xml2-dir
        --with-xml2-include
        --without-xml2-include=${xml2-dir}/include
        --with-xml2-lib
        --without-xml2-lib=${xml2-dir}/lib
        --with-libxml-2.0-config
        --without-libxml-2.0-config
        --with-pkg-config
        --without-pkg-config
        --with-xslt-dir
        --without-xslt-dir
        --with-xslt-include
        --without-xslt-include=${xslt-dir}/include
        --with-xslt-lib
        --without-xslt-lib=${xslt-dir}/lib
        --with-libxslt-config
        --without-libxslt-config
        --with-pkg-config
        --without-pkg-config
        --with-exslt-dir
        --without-exslt-dir
        --with-exslt-include
        --without-exslt-include=${exslt-dir}/include
        --with-exslt-lib
        --without-exslt-lib=${exslt-dir}/lib
        --with-libexslt-config
        --without-libexslt-config
        --with-pkg-config
        --without-pkg-config

extconf failed, exit code 1
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Abram
  • 39,950
  • 26
  • 134
  • 184

2 Answers2

2

I had the same problem and tried a lot of options but what I needed were these two libraries:

libxml2-devel
libxslt-devel

The thing is the output always mentioned libxml2 but the needed stuff seemed to be in the development library. (I'm not really into libraries and stuff so I can't tell exactly what the porblem was.) I use Cent OS so maybe its a bit different with your setup (something like libxml2-dev libxslt1-dev).

Lorro
  • 88
  • 9
1

Installing zlib1g-dev prior to installing the gem should resolved it. For CentOS:

yum install zlib-devel

In version 1.6.6.1 developers restored checking if zlib is available before building libxml2.

This solved this problem for me:

gem 'nokogiri', '1.6.7.rc2'
Artyom Kalmykov
  • 390
  • 1
  • 9
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Drenmi Oct 22 '15 at 12:32
  • @Drenmi How does this not provide an answer? It presents a plausible solution. If you believe it is incorrect, you should down vote and leave a comment explaining your concerns. We shouldn't try to delete 'wrong' answers from review. – Undo Oct 22 '15 at 22:41
  • @Undo: After rethinking, I'm leaning slightly more towards your stance, but still conflicted. Just telling people to use another version might treat the symptoms, but don't address the actual cause of the problem. – Drenmi Oct 23 '15 at 04:15
  • Thank you, I edit my answer. Hope it will help the author. – Artyom Kalmykov Oct 23 '15 at 08:42