Nokogiri gem install failing in Capistrano deploy

此生再无相见时 提交于 2020-01-25 01:40:25

问题


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

回答1:


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




回答2:


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'


来源:https://stackoverflow.com/questions/31222528/nokogiri-gem-install-failing-in-capistrano-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!