简体   繁体   中英

Error installing rails ERROR: Failed to build gem native extension

I have this problem on my linux OS:

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

How do I fix this issue from the above logs?

When I run sudo apt-get install ruby-dev zlib1g-dev liblzma-dev I got these logs:

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

So to solve this problem I run apt-get -f install

Then I run sudo apt-get install ruby-dev zlib1g-dev liblzma-dev dependencies were successfully installed.

gem native extension successfully build.

我在使用ruby2.4.4-alpine和ruby2.4.4-slim Docker镜像时遇到了相同的错误,只是更改为ruby2.4.4-jasmine解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM