Nokogiri v 1.8.1 issue when running Bundle Install
Asked Answered
H

8

13

When running Bundle Install or Gem Install Nokogiri, I get the same issue which is preventing my app from running. I suspect this issue is local and came from moving everything up to Rails 5, but I'm not sure. Here is the error message:

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_admin was resolved to 1.2.0, which depends on
    rails was resolved to 5.1.3, which depends on
      actioncable was resolved to 5.1.3, which depends on
        actionpack was resolved to 5.1.3, which depends on
          actionview was resolved to 5.1.3, which depends on
            rails-dom-testing was resolved to 2.0.3, which depends on
              nokogiri

(That comes from running Bundle Install) I've tried running Bundle Update and using various Homebrew commands recommended by Github, but I haven't had any success.

gem install nokogiri -v '1.8.1'

1 error generated.
make[2]: *** [xmlIO.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
========================================================================
*** 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.
Hoitytoity answered 31/10, 2017 at 15:0 Comment(5)
Have you tried running brew doctor? Might have to relink a few things.Subaqueous
Did you try running gem install nokogiri -v '1.8.1 ?Cameliacamella
@Cameliacamella I just tried it, I updated the post with the error from thatHoitytoity
OK run gem update --system then install xcode cl tools xcode-select --install and finally re run the gem installation gem install nokogiri. let me know if that helpedCameliacamella
In my case this error started happening after installing a software update to xcode. @Cameliacamella your suggestion fixed the problem for me. Perhaps you could make that an answer?Correll
A
6

Nokogiri fails to build normaly because you don't have dev libraries like libxml2. Look at the log file to see what happens or try to install libxml2 directly with brew install libxml2

See throubleshoting guide provided by Nokogiry at http://www.nokogiri.org/tutorials/installing_nokogiri.html

Adne answered 31/10, 2017 at 16:25 Comment(1)
I have the dev version of libxml2 installed its failing for meCandelaria
P
13

(for UBUNTU) First try to do this

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

then try to install.

Pissarro answered 23/1, 2018 at 14:0 Comment(1)
This might have changed slightly since you wrote it, but what worked for me was: sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev From the official Nokogiri installation instructionsSafekeeping
C
13

I'm just posting the solution I found (I had the same problem on MacOS). With this, the gem will be installed using the system libraries, which should solve the probleme you encountered.

  1. If using gem:
gem install nokogiri -- --use-system-libraries
 [--with-xml2-config=/path/to/xml2-config]
 [--with-xslt-config=/path/to/xslt-config]
  1. If using bundle:
bundle config build.nokogiri --use-system-libraries
bundle install
Cinerary answered 1/2, 2019 at 9:58 Comment(2)
In my case 2. if using bundle works fine. Thank you for a solution.Ranite
You're very welcome, glad I could help someone out. :)Cinerary
A
6

Nokogiri fails to build normaly because you don't have dev libraries like libxml2. Look at the log file to see what happens or try to install libxml2 directly with brew install libxml2

See throubleshoting guide provided by Nokogiry at http://www.nokogiri.org/tutorials/installing_nokogiri.html

Adne answered 31/10, 2017 at 16:25 Comment(1)
I have the dev version of libxml2 installed its failing for meCandelaria
C
2

Here are the steps that might help you solve this issue:

  1. gem update --system

  2. Install the Xcode command line tools: xcode-select --install

  3. Finally now install Nokogiri: gem install nokogiri

Cameliacamella answered 29/3, 2018 at 6:54 Comment(2)
happened to me after updating to ruby 3.5 - this fixed it. but the command flags should be --system and --installConfidential
Go on then! ;) :)Frostwork
H
2

On high sierra (and mojave), this worked for me

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/

bundle update

bundle install
Hatchet answered 19/2, 2019 at 11:57 Comment(1)
This is gonna update the version of every gem in the Gemfile.Halloran
P
1

libxml2 and zlib is required for building, you need to install both.

Fedora:

sudo dnf install libxml2-devel zlib-devel

Ubuntu:

sudo apt install libxml2-dev zlib1g-dev 
Poppyhead answered 13/9, 2018 at 20:11 Comment(1)
i have both libxml2 and zlib dev version its still failing for meCandelaria
C
0

Had the same issue after I upgraded Xcode

I had to run: sudo xcode-select --switch /Library/Developer/CommandLineTools/ then: sudo bundle install --system

After that everything was fine.

Chronological answered 25/8, 2018 at 18:50 Comment(0)
L
0

If using MAC OS You can try to

brew unlink xz
gem install nokogiri
brew link xz

I use MAC OS, and using brew install ruby to avoid messing up with the system's ruby environment, and the following bundle install goes very smoothly.

Lourdeslourie answered 23/9, 2018 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.