Installing Nokogiri on an M1 Mac
If you're working with Ruby projects, it's likely you'll have encountered Nokogiri.
Nokogiri, as a very powerful library for XML/HTML parsing, is used by many dependencies, but for Ruby devs is consistently an awkward thing to install, as it requires native extensions.
If you've got an M1 Mac, you may be hitting issues such as:
dlopen(.../nokogiri/.../nokogiri.bundle, ...): could not use '.../nokogiri-.../lib/nokogiri/.../nokogiri.bundle' because it is not a compatible arch - .../nokogiri-.../lib/nokogiri/.../nokogiri.bundle (LoadError)```
This is due to Bundler not picking up the platform's architecture correctly.
If you're on the default Ruby installation, which has a bundle --version
below v2.1, you'll need to run, thanks to this comment on StackOverflow:
bundle config set force_ruby_platform true
bundle install
Or when using a Bundler version above v2.1
:
bundle config force_ruby_platform true
bundle install