12

bundle:install阶段之后deploy:finalize_update,我收到关于 nokogiri 的错误。它表明,

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

所以我尝试自己在服务器上安装nokogiri。但它给出了以下错误,

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

它今天才开始。libxml2 也已经安装。

任何的想法?

谢谢。

编辑:我不需要在我的 gemfile 中明确地 nokogiri。

4

4 回答 4

37

我在 Nokogiri 1.6.0 中遇到了同样的问题。从日志中可以看出,该问题是由 libxml2 编译失败引起的,libxml2 与 libxslt 一起被嵌入到 gem 中并在安装时编译。

要找出编译到底出了什么问题,请查看建议的文件compile.log,根据您的情况,您可以在以下位置找到:

/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

作为一种解决方法(假设您安装了 libxml2-dev 和 libxslt-dev),您可以执行以下操作:

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install

我希望它有所帮助。

于 2013-06-24T15:57:08.857 回答
11

如果您使用 Capistrano 3.x,您可以在您的deploy.rb文件(或环境特定文件,即deploy/production.rb)中执行以下操作

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

这样可以避免覆盖bundle install任务。这将在运行时设置给定的env变量bundle install

于 2014-03-27T16:20:20.000 回答
0

根据@zekus 的回答,我在 capistrano 中创建了一个新任务,如下所示:

  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"

这对我很有效。

于 2013-11-01T19:21:45.770 回答
0

使用部署者用户连接到您的主机,而不是尝试自己安装包:

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

比手动运行 capistrano。

这对我有用。

于 2015-04-29T12:19:45.960 回答