安装rails时出错ERROR:无法构建gem native扩展

时间:2017-11-20 08:52:53

标签: ruby-on-rails ruby ruby-on-rails-5

我的linux操作系统出现了这个问题:

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

    current directory: /var/lib/gems/2.3.0/gems/nokogiri-1.8.1/ext/nokogiri
/usr/bin/ruby2.3 -r ./siteconf20171120-5536-amlck4.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

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

如何从上述日志中解决此问题?

2 个答案:

答案 0 :(得分:1)

当我运行sudo apt-get install ruby-dev zlib1g-dev liblzma-dev时,我收到了这些日志:

build-essential patch
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
patch is already the newest version (2.7.5-1).
zlib1g-dev is already the newest version (1:1.2.8.dfsg-2ubuntu4.1).
zlib1g-dev set to manually installed.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 ruby-dev : Depends: ruby2.3-dev but it is not going to be installed
 slack-desktop : Depends: libappindicator1 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

为了解决这个问题,我运行apt-get -f install

然后我运行sudo apt-get install ruby-dev zlib1g-dev liblzma-dev个依赖项已成功安装。

gem native extension成功构建。

答案 1 :(得分:1)

我使用ruby2.4.4-alpine和ruby2.4.4-slim Docker图像得到了同样的错误,只是改为ruby2.4.4-jasmine解决了这个问题。