ruby on rails - problem bundle install nokogiri 1.7.2 on ruby on rails 4.x
Asked Answered
C

4

5

I have problem trying to do bundle install nokogiri 1.7.2

I am using

gem 'rails', '4.2.4'
MacOS High Sierra version 10.13.6

Im not sure what is wrong

below is my error output:

full error output:

https://gist.github.com/axilaris/68e7df57c3e29366d7a1998eebd93517

this is where the error description:

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

In Gemfile:
  rails_admin was resolved to 1.1.1, which depends on
    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

UPDATE, didnt work with sudo gem install nokogiri

$ sudo gem install nokogiri -v '1.7.2'
Building native extensions.  This could take a while...

....

Building Nokogiri with a packaged version of libxml2-2.9.4
with the following patches applied:
    - 0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch
    - 0002-Fix-XPointer-paths-beginning-with-range-to.patch
    - 0003-Disallow-namespace-nodes-in-XPointer-ranges.patch

Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:

    gem install nokogiri -- --use-system-libraries
        [--with-xml2-config=/path/to/xml2-config]
        [--with-xslt-config=/path/to/xslt-config]

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.4.tar.gz into tmp/x86_64-apple-darwin17/ports/libxml2/2.9.4... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0001-Fix-comparison-with-root-node-in-xmlXPathCmpNodes.patch... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0002-Fix-XPointer-paths-beginning-with-range-to.patch... OK
Running git apply with /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/patches/libxml2/0003-Disallow-namespace-nodes-in-XPointer-ranges.patch... OK
Running 'configure' for libxml2 2.9.4... OK
Running 'compile' for libxml2 2.9.4... ERROR, review '/Library/Ruby/Gems/2.3.0/gems/nokogiri-1.7.2/ext/nokogiri/tmp/x86_64-apple-darwin17/ports/libxml2/2.9.4/compile.log' to see what happened. Last lines are:
...

Maybe related to this ? https://github.com/sparklemotion/nokogiri/issues/1690

UPDATE 18.9.2018

I noticed major issue with my rails environment on my laptop. i tried to create a new rails app. nokogiri causing major issues to my environment. what is the issue and how to resolve this ? https://gist.github.com/axilaris/03882e15d2cbd603279a654547752f9c

Circumlocution answered 4/9, 2018 at 14:56 Comment(3)
Do you use homebrew? Try installing libxml with homebrew. Or using macs native libxml.Ashy
have you tried homebrew libxml2 ? and then trying to install the gem again?Purlin
im not sure. its been sometime. whats the command to install libxml2 ? is it brew install libxml2Circumlocution
S
3

Sometimes happens to me as well, in which case I just install nokogiri via gem install nokogiri -v '1.7.2' as the error suggests. If that fails, try gem uninstall nokogiri -v '1.7.2' first and retry...

As mentioned by xploshioOn, use sudo gem install as last resort.

Speight answered 4/9, 2018 at 15:21 Comment(3)
strangely, it suddenly works. i somehow got back and did bundle install and it works. its very strange. i'll just give it a right on you since you have experience on this.Circumlocution
actually it didnt quite work. but the output shows something that relates to libxml2 error. maybe related to this github.com/sparklemotion/nokogiri/issues/1690. not sure what to do yet.Circumlocution
it's a bad idea to install gems with sudo. avoid it as possiblePurlin
M
3

Sometimes this is a pain, I'm not even sure why this happens randomly. however, here is how I solve it most of the time.

brew unlink xz
gem install nokogiri
brew link xz

If that does not help, throws an error again with libxml2, you should do the following

brew install libxml2

and then

gem install nokogiri -- --use-system-libraries \
  --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
Mohler answered 14/9, 2018 at 7:34 Comment(8)
what is brew unlink xz ?Circumlocution
i get this ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.Circumlocution
xz is a command line tool, which could be causing the issue, it's better you uninstall brew uninstall xz and try to install nokogiri. Also, try not to do things using sudoMohler
Error: Refusing to uninstall /usr/local/Cellar/xz/5.2.3 because it is required by imagemagick, imagemagick@6, python, which are currently installed.Circumlocution
brew unlink xz works. but brew uninstall xz does not work due to the dependenciesCircumlocution
Have you tried to downgrade the version and install nokogiri ? like 1.6.8 ?Mohler
hmm... i dont see nokogiri in my Gemfile. I can see it only in the Gemfile.lock file as nokogiri (>= 1.5.11, < 2.0.0). do i modify there ? or how ?Circumlocution
Let us continue this discussion in chat.Mohler
A
2

You can allow bundler to resolve dependencies again with

  • run brew upgrade libxml2
  • remove block code in Gemfile.lock file, starting from rails_admin till next blank line
  • save the file
  • run bundle install
Attested answered 14/9, 2018 at 16:8 Comment(6)
$ brew upgrade libxml2 Error: libxml2 2.9.7 already installedCircumlocution
@Circumlocution so just skip it and go to next stepAttested
this is my Gemfile.lock gist.github.com/axilaris/816f49e2aa63931f621c6d95f912c871 and i should modify it like this ? gist.github.com/axilaris/fff9dd107323ab7db9a9830cd2b06ceeCircumlocution
@Axil, oh man no, I read you error and it looks like you need to relink problem dependency. Try to do it with brew unlink xz and then brew link xz. And then try bundle install againAttested
ok done the above, can you double check if this is correct. this is my Gemfile.lock gist.github.com/axilaris/816f49e2aa63931f621c6d95f912c871 and i should modify it like this ? gist.github.com/axilaris/fff9dd107323ab7db9a9830cd2b06ceeCircumlocution
btw i have an UPDATE in my comment, something terribly wrong with the environment.Circumlocution
H
0

Once, my Mac could not find the libxml2 library until I had accepted xCode's license agreement:

sudo xcodebuild -license accept

You may also want to encourage the machine to use the xCode libxml2:

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/
Huehuebner answered 12/9, 2018 at 20:18 Comment(3)
still error. "You don't have write permissions for the /usr/bin directory". i tried even with sudo. here is how i tried it. gist.github.com/axilaris/c4f1c33d3afab023cde3c498a41cffd2Circumlocution
Hm, what version of Ruby are you using? Are you using RVM? I think this can be caused by certain versions of Ruby -- maybe by the system version in High Sierra.Huehuebner
I would strongly recommend RVM to address this problem. It will give you control over your Ruby version.Huehuebner

© 2022 - 2024 — McMap. All rights reserved.