nokogiri gem - 错误:无法构建gem原生扩展。

时间:2017-11-13 23:13:49

标签: ruby-on-rails ruby ubuntu

我正在尝试使用capistrano部署rails应用程序,但是当在服务器ubuntu 16.04中进行捆绑安装时,我遇到了nokogiri gem的一些问题

回溯如下:

Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as root@104.236.11.204: bundle exit status: 5
bundle stdout: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/var/www/denunciabarranquillafinal/shared/bundle/ruby/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20171113-30499-1nk84ws.rb
extconf.rb --use-system-libraries
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -r
./siteconf20171113-30499-1nk84ws.rb extconf.rb --use-system-libraries 2>&1

Gem files will remain installed in
/var/www/denunciabarranquillafinal/shared/bundle/ruby/2.3.0/gems/nokogiri-1.8.1
for inspection.
Results logged to
/var/www/denunciabarranquillafinal/shared/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.8.1/gem_make.out

An error occurred while installing nokogiri (1.8.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.8.1'` succeeds before bundling.

In Gemfile:
  rails was resolved to 4.2.4, which depends on
    actionmailer was resolved to 4.2.4, which depends on
      actionpack was resolved to 4.2.4, which depends on
        actionview was resolved to 4.2.4, which depends on
          rails-dom-testing was resolved to 1.0.8, which depends on
            nokogiri
bundle stderr: Nothing written

我运行了命令

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev

在我的服务器中,如果我运行“gem install nokogiri”,宝石就会正常安装。

我希望有人可以帮我解决错误。

2 个答案:

答案 0 :(得分:1)

试试这个:

$ sudo apt-get update 
$ sudo apt-get install libxml2-dev libxslt-dev
$ sudo gem install nokogiri

答案 1 :(得分:0)

我知道这是该线程启动之后的几年,但是我对nokogiri和capybara遇到了同样的问题。我在Ubuntu 20.04上,但在Ubuntu 18.04上也有相同的问题-同一台计算机。

sudo apt-get update
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
sudo apt-get install libxml2-dev libxslt-dev
sudo gem install nokogiri
sudo gem install capybara

我尽了一切可能,但似乎没有任何效果。我不确定它做了什么,但是上面是我尝试的最后一个命令行命令。 of ...终于奏效了。