Reputation: 111
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 :)
Upvotes: 1
Views: 482
Reputation: 2099
... 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:
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)
$ rvm gemset empty
$ gem install bundler
$ 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:
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.
Upvotes: 2
Reputation: 111
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.3
where rails 5.2.2 was still installed. I re-installed sqlite3 with gem install sqlite3
and 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!
Upvotes: 0
Reputation: 55002
According to them it's:
brew install libxml2
gem install nokogiri -- --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle config build.nokogiri --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
bundle install
Upvotes: 2