Error about nokogiri while capistrano deployment on ubuntu server
Asked Answered
G

4

12

While bundle:install phase after deploy:finalize_update,i'm getting an error about nokogiri. It suggests ,

 ** [out :: *******] Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.

So i tried to install nokogiri by myself on server.But it gives following error,

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

    /home/deployer/.rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-linux-gnu/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-linux-gnu/ports/libxml2/2.8.0/compile.log' to see what happened.
*** 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/deployer/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
/home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.5.0/lib/mini_portile.rb:235:in `block in execute': Failed to complete compile task (RuntimeError)
    from /home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.5.0/lib/mini_portile.rb:227:in `chdir'
    from /home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.5.0/lib/mini_portile.rb:227:in `execute'
    from /home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.5.0/lib/mini_portile.rb:61:in `compile'
    from /home/deployer/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/gems/2.0.0/gems/mini_portile-0.5.0/lib/mini_portile.rb:101:in `cook'
    from extconf.rb:101:in `block in <main>'
    from extconf.rb:119:in `call'
    from extconf.rb:119:in `block in <main>'
    from extconf.rb:109:in `tap'
    from extconf.rb:109:in `<main>'


Gem files will remain installed in /home/deployer/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.6.0 for inspection.
Results logged to /home/deployer/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out

It just started today.Also libxml2 is already installed.

Any idea?

Thanks.

EDIT: I dont require explicitly nokogiri in my gemfile.

Grosvenor answered 20/6, 2013 at 12:31 Comment(3)
I have an idea: review 'tmp/x86_64-linux-gnu/ports/libxml2/2.8.0/compile.log' to see what happened.Argot
:) file does not existChronological
I added nokogiri to my gem file and its solved. But gives me a warning. WARNING: Nokogiri was built against LibXML version 2.9.1, but has dynamically loaded 2.8.0Chronological
K
37

I faced the same issue with Nokogiri 1.6.0. The problem, as you can see from the logs, it's caused by a failed compilation of libxml2 that, together with libxslt, is now shipped embedded in the gem and compiled when you install it.

To find out what exactly went wrong with the compilation, have a look at the suggested file compile.log that, in your case, you can find at:

/home/deployer/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.6.0/ext/nokogiri/tmp/x86_64-linux-gnu/ports/libxml2/2.8.0/compile.log

As a workaround (assuming you have libxml2-dev and libxslt-dev installed), you can do:

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

I hope it helps.

Komara answered 24/6, 2013 at 15:57 Comment(3)
Thanks for the workaround! I think its definately a homebrew issue for me, but no time to Google-Fu the fix.Alate
you workaround worked for me too. but still giving me warning. any opened issue about this? maybe we can attach this question to it.Chronological
It should be expanded to include the answer from @tiagoHuffy
S
11

If you're using Capistrano 3.x you can do the following in your deploy.rb file (or environment specific file i.e. deploy/production.rb)

set :bundle_env_variables, { 'NOKOGIRI_USE_SYSTEM_LIBRARIES' => 1 }

This way you avoid overriding the bundle install task. This will set the given env variables when running bundle install.

Sudor answered 27/3, 2014 at 16:20 Comment(0)
T
0

Based on @zekus answer, I created a new task in capistrano like this:

  task :custom_bundle_install, roles: :app do
    run "cd /home/#{user}/apps/#{application}/releases/#{release_name} && NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --gemfile /home/#{user}/apps/#{application}/releases/#{release_name}/Gemfile --path /home/#{user}/apps/#{application}/shared/bundle --deployment --quiet --without development test"
  end
  before "bundle:install", "deploy:custom_bundle_install"

This worked for me pretty well.

Tinner answered 1/11, 2013 at 19:21 Comment(0)
I
0

Connect to you host with deployer user, than try install bundle by yourself:

cd {your last release path}
bundle config build.nokogiri --with-xml2-include=/usr/include/libxml2/libxml
bundle install --gemfile Gemfile --path shared/bundle --deployment --quiet --without development test

Than run capistrano manually.

This worked for me.

Insight answered 29/4, 2015 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.