Fixing Failed to build nokogiri 1.8.3 gem Fedora 28

Today I talk about how I fixed “Failed to build nokogiri 1.8.3” on Fedora 28.

Whats the issue with nokogiri 1.8.3 on Fedora 28?

At the moment any ruby applications that requires nokogiri 1.8.3 in the Gemfile will fail to build. This is due to an issue with the libraries packaged in Fedora.

As far as I can tell from the bug reports, this is only present in Fedora due to how ruby and the dev files are packaged.

Commonly this is shown up with a similar error to:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /usr/share/gems/gems/nokogiri-1.8.3/ext/nokogiri
/usr/bin/ruby -r ./siteconf20180624-5605-fp1465.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /usr/share/gems/gems/nokogiri-1.8.3 for
Results logged to /usr/lib64/gems/ruby/nokogiri-1.8.3/gem_make.out

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

In Gemfile:
rails was resolved to 4.2.8, which depends on
actionmailer was resolved to 4.2.8, which depends on
actionpack was resolved to 4.2.8, which depends on
actionview was resolved to 4.2.8, which depends on
rails-dom-testing was resolved to 1.0.9, which depends on

Fixing this by changing the Gemfile requirements

I got this error because I was installing Redmine which required the nokogiri version to be:

gem "nokogiri", (RUBY_VERSION >= "2.1" ? "~> 1.8.1" : "~> 1.6.8"

This selected the 1.8.3 version of nokogiri which as above it is impossible to install currently.

To resolve this I installed the nokogiri in Fedora using the following command:

sudo dnf install rubygem-nokogiri

After installing I noted down which version it had installed by reading the install log (example below).

rubygem-nokogiri.x86_64 1.8.2-1.fc28

Once I had worked out that I have installed 1.8.2 I then went back into the gemfile. By modifying it to specify nokogiri should use 1.8.2 (the version I just installed) the install then worked fine. I changed the gemfile to say:

gem "nokogiri", "1.8.2"

After changing this I was able to install redmine as expected using bundler install.

It is hoped that the issue with this package will be resolved quickly and the Fedora project will update the version in dnf however until then this fix will resolve the issue.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.