1

I really hate these updates in Ruby/Rails....

I have a Mac High Sierra OSX 10.13. I last used Ruby/Rails about a year ago, so of course I needed to update stuff. I have gone around and around the update carousell, but what I am stuck on is this:

Nokogiri was built against LibXML version 2.9.4, but has dynamically loaded 2.7.8

I find lots of questions with older versions of Nokogiri and LibXML, but none with these newer versions. I've tried all of the answers, too.

I think the problem might be that I updated xcode (although I never use it, I prefer sublime) before I left for traveling, and now I have the xcode for OSX 10.14 installed.

Is there any way I can make Nokogiri build against 2.7.8? I only wanted to demonstrate to a class how cool Ruby on Rails is (and right now I don't see it as being cool at all). I tried

gem install nokogiri -- --use-system-libraries --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.8

but it still built against libxml2 2.9.4!

Would love to get this solved in 2018 :)

  • 1
    Does nokogiri not actually work, or are you just seeing a warning that can be ignored? If not working, can you `gem uninstall` and `gem install` it? Finally, are you using system Ruby or a version installed by a manager like RVM? If you're using system Ruby then stop using system Ruby, install RVM with `\curl -sSL https://get.rvm.io | bash -s stable`; install Ruby with `rvm install 2.5.3`, and then `gem install nokogiri`. – anothermh Dec 29 '18 at 18:39
  • It's not actually working. If it was just a warning I would ignore it :) But trying to start the rails server (rails new works) crashes in burning flames. I've tried gem uninstall and gem install. I'll give the RVM a try, I've been using the system Ruby. – Debora Weber-Wulff Dec 29 '18 at 20:14
  • [Don't](https://robots.thoughtbot.com/psa-do-not-use-system-ruby) [use](https://chrisherring.co/posts/why-you-shouldn-t-use-the-system-ruby) [system Ruby](http://billpatrianakos.me/blog/2014/05/15/never-use-system-ruby-ever/). – anothermh Dec 29 '18 at 20:28
  • Ah yes, I have been reminded of DLL hell many times this afternoon and evening. I have also tried the sudo gem install bit, as that was one of the suggestions someone made. Currently stuck at No binary rubies available for: osx/10.13/x86_64/ruby-2.5.3. Installed rubygems 2.7.6 is newer than 2.6.14 provided with installed ruby, skipping installation, use --force to force installation but it says "this may take a while depending on your cpu", so I'll wait another hour. Thanks! – Debora Weber-Wulff Dec 29 '18 at 20:38
  • If you're using RVM then using `sudo gem` will fuck everything up. Just use `gem`. Also RVM doesn't install binary versions; it compiles Ruby from source. Give it time. And the comparison to DLL hell makes no sense here; RVM installs everything it needs into `~/.rvm`; any issues with it, the Rubies it installs, or the gems it installs can be resolved by `rm -rf ~/.rvm` and reinstalling RVM and Ruby. – anothermh Dec 29 '18 at 20:46
  • Oh, I didn't mean that RVM was DLL hell, but that futzing around with all the gems was. I haven't used RVM before, so I'll let it run a bit more and see. rmv wouldn't install ruby, said it was already there. But I could do "rvm reinstall ruby-2.5.3", which I did. That compiled from scratch (something I approve of) and is now hanging at "ruby-2.5.3 - #making binaries executable.." I'll wait! – Debora Weber-Wulff Dec 29 '18 at 21:19
  • Nope, installed rvm, used that to install ruby, then nodejs, and rails. Attempted to gem install nokogiri, and I get the old "libxml2 is missing" and it crashes. – Debora Weber-Wulff Dec 29 '18 at 22:22
  • Run `brew doctor` and `brew update` and `brew upgrade libxml2` and then `gem install nokogiri`. – anothermh Dec 29 '18 at 22:25
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/185921/discussion-between-debora-weber-wulff-and-anothermh). – Debora Weber-Wulff Dec 29 '18 at 22:52

3 Answers3

2

According to them it's:

brew install libxml2

If installing directly

gem install nokogiri -- --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

If using Bundle

bundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

bundle install

pguardiario
  • 53,827
  • 19
  • 119
  • 159
  • Now getting Permission denied @ rb_sysopen - /usr/local/rvm/gems/ruby-2.5.3/gems/nokogiri-1.9.1/LICENSE-DEPENDENCIES.md I'm afraid I have mixed up too many ruby environments. Is there any way to cleanly remove ALL rubys (I have 5 on my machine) and rails and start over with a clean slate? Mac OSX 10.13.... – Debora Weber-Wulff Dec 29 '18 at 23:52
  • I rebooted, and the permission denied went away... If I use the installing directly command above, I get "Successfully installed nokogiri-1.9.1" BUT, when trying to start the rails server I again get "WARNING: Nokogiri was built against LibXML version 2.9.4, but has dynamically loaded 2.7.8" I've re-installed rails, same problem. Any ideas? – Debora Weber-Wulff Dec 30 '18 at 00:24
  • Try the bundle lines. – pguardiario Dec 30 '18 at 01:52
2

... it works on my machine ... ;-)

Although the Nokogiri Tutorial suggests handcrafting your local environment in complicated ways - see https://www.nokogiri.org/tutorials/installing_nokogiri.html - if adhering to any of these suggestions at all, I would escape ahead and try the direction of updating the system library rather than trying to make Nokogiri build against the older one, if only for the fact that if you install the gems using bundler you wouldn't want to mess around with manual gem installations, anyway. (Except for troubleshooting to retry this one gem over and over again until it works and then make sure bundler can do it, as well - but installing Nokogiri isn't the problem here).

... because: while you may not want to install on a web server at the end, adhering to the principle of declaring and isolating dependencies with the app as described in https://12factor.net/dependencies is still a great idea.

And bundler and rvm (or rbenv) are the tools for that in the ruby/rails world (or, for that matter, bundler and docker, which I wouldn't recommend in that situation).

If it still doesn't work with rvm, I would do the following:

  • use rvm with gemsets.
  • make sure that the current shell uses the exact gemset and ruby version you want. Always.

    rvm use 2.5.1@my-gemset --create --ruby-version

(with the appropriate ruby version) creates a ruby-version+gemset combination and creates .ruby-* files in the dir making sure this gemset is used when you cd in this dir. all my rails-apps have this. your path above shows that rvm throws all gems for one ruby version in one directory)

  • delete all gems in the gemset: $ rvm gemset empty
  • and reinstall them:
  • run: $ gem install bundler
  • and then: $ bundle install

(this is a rude but efficient way to have rvm make sure that your app / rails / bundler won't pick up another version of any gem lingering around in your system-wide or rvm-ruby-version-wide gem folder - none of your logs showed which version of Nokogiri was actually running)

you can check on the gems in your gemset with `ls $(rvm gemset dir)/gems


nb: one of the Stack Overflow answers on this topic suggests putting gem rails on the top of the Gemfile:

How to load correct version of dynamic libraries and gems (libxml, Nokogiri) within a custom Rails engine gem?

and indeed, Gemfile order matters starting up rails:

Does the order of gems in your Gemfile make a difference?

so this might be a good idea, as well.

bento
  • 2,079
  • 1
  • 16
  • 13
  • After rvm gemset empty I had to first install bundle again :) Still doesn't work, same error. Doesn't work for me.... So I stepped back to Ruby 2.3.3 with rvm. Here, Rails 5.2.2 is installed. I can create a new project, everything looks fine. Rails is on top of the Gemfile, and next is sqllite3 (without a version number, is that maybe the problem)? But rails server gives me the exact same bail I have been seeing since yesterday. Any ideas? Reinstall sqllite3? – Debora Weber-Wulff Dec 30 '18 at 14:22
0

Alright, I found a bizarre sequence that works enough for me to get through an "Introduction to Rails" lecture:

Go back to Ruby 2.3.3 with rvm use 2.3.3where rails 5.2.2 was still installed. I re-installed sqlite3 with gem install sqlite3and then build install. Now I can start a server!

I tried it again with Ruby 2.5.3 in a new rvm gemset. sqlite3 is installable, gem install rails gets a permission error, so I have to rvmsudo gem install rails and this bails with the nokogiri problem. I tried to bundle install after setting

bundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2

and I just get Could not locate Gemfile

I can go back to 2.3.3 and so that's what I'm going to do for now. But something is screwed up somewhere.... Thanks for all the help!