MacOs (M1 Arm64) unable to load Nokogiri - Using system default Ruby
Asked Answered
L

4

19

I could use some help here. I'm setting up a new 2020 Macbook Pro M1.

I've completed all the regular steps to install ruby/rails on a Mac, however I'm unable to complete rails new. Upon hitting the following part of the install I get this error:

E*****@Admins-MBP desktop % rails new testapp
      create  
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  .gitattributes
      create  Gemfile
         run  git init from "."
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:   git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:   git branch -m <name>
Initialized empty Git repository in /Users/E****/Desktop/testapp/.git/
      create  package.json
      create  app
      create  app/assets/config/manifest.js
      create  app/assets/stylesheets/application.css
      create  app/channels/application_cable/channel.rb
      create  app/channels/application_cable/connection.rb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/javascript/channels/consumer.js
      create  app/javascript/channels/index.js
      create  app/javascript/packs/application.js
      create  app/jobs/application_job.rb
      create  app/mailers/application_mailer.rb
      create  app/models/application_record.rb
      create  app/views/layouts/application.html.erb
      create  app/views/layouts/mailer.html.erb
      create  app/views/layouts/mailer.text.erb
      create  app/assets/images
      create  app/assets/images/.keep
      create  app/controllers/concerns/.keep
      create  app/models/concerns/.keep
      create  bin
      create  bin/rails
      create  bin/rake
      create  bin/setup
      create  bin/spring
      create  bin/yarn
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/cable.yml
      create  config/puma.rb
      create  config/spring.rb
      create  config/storage.yml
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/application_controller_renderer.rb
      create  config/initializers/assets.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/content_security_policy.rb
      create  config/initializers/cookies_serializer.rb
      create  config/initializers/cors.rb
      create  config/initializers/filter_parameter_logging.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_framework_defaults_6_1.rb
      create  config/initializers/permissions_policy.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/master.key
      append  .gitignore
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  lib
      create  lib/tasks
      create  lib/tasks/.keep
      create  lib/assets
      create  lib/assets/.keep
      create  log
      create  log/.keep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/apple-touch-icon-precomposed.png
      create  public/apple-touch-icon.png
      create  public/favicon.ico
      create  public/robots.txt
      create  tmp
      create  tmp/.keep
      create  tmp/pids
      create  tmp/pids/.keep
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor
      create  vendor/.keep
      create  test/fixtures/files
      create  test/fixtures/files/.keep
      create  test/controllers
      create  test/controllers/.keep
      create  test/mailers
      create  test/mailers/.keep
      create  test/models
      create  test/models/.keep
      create  test/helpers
      create  test/helpers/.keep
      create  test/integration
      create  test/integration/.keep
      create  test/channels/application_cable/connection_test.rb
      create  test/test_helper.rb
      create  test/system
      create  test/system/.keep
      create  test/application_system_test_case.rb
      create  storage
      create  storage/.keep
      create  tmp/storage
      create  tmp/storage/.keep
      remove  config/initializers/cors.rb
      remove  config/initializers/new_framework_defaults_6_1.rb
         run  bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.6
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
  /usr/local/bin
Using concurrent-ruby 1.1.9
Using i18n 1.8.10
Using minitest 5.14.4
Using tzinfo 2.0.4
Using zeitwerk 2.5.1
Using activesupport 6.1.4.1
Using builder 3.2.4
Using erubi 1.10.0
Using mini_portile2 2.6.1
Using racc 1.6.0
Using nokogiri 1.12.5 (x86_64-darwin)
Using rails-dom-testing 2.0.3
Using crass 1.0.6
Using loofah 2.12.0
Using rails-html-sanitizer 1.4.2
Using actionview 6.1.4.1
Using rack 2.2.3
Using rack-test 1.1.0
Using actionpack 6.1.4.1
Using nio4r 2.5.8
Using websocket-extensions 0.1.5
Using websocket-driver 0.7.5
Using actioncable 6.1.4.1
Using globalid 0.5.2
Using activejob 6.1.4.1
Using activemodel 6.1.4.1
Using activerecord 6.1.4.1
Using marcel 1.0.2
Using mini_mime 1.1.2
Using activestorage 6.1.4.1
Using mail 2.7.1
Using actionmailbox 6.1.4.1
Using actionmailer 6.1.4.1
Using actiontext 6.1.4.1
Using public_suffix 4.0.6
Using addressable 2.8.0
Using bindex 0.8.1
Using msgpack 1.4.2
Using bootsnap 1.9.1
Using bundler 1.17.2
Using byebug 11.1.3
Using matrix 0.4.2
Using regexp_parser 2.1.1
Using xpath 3.2.0
Using capybara 3.36.0
Using childprocess 4.1.0
Using ffi 1.15.4
Using jbuilder 2.11.2
Using rb-fsevent 0.11.0
Using rb-inotify 0.10.1
Using listen 3.7.0
Using method_source 1.0.0
Using puma 5.5.2
Using rack-mini-profiler 2.3.3
Using rack-proxy 0.7.0
Using thor 1.1.0
Using railties 6.1.4.1
Using sprockets 4.0.2
Using sprockets-rails 3.2.2
Using rails 6.1.4.1
Using rexml 3.2.5
Using rubyzip 2.3.2
Using sassc 2.4.0
Using tilt 2.0.10
Using sassc-rails 2.1.2
Using sass-rails 6.0.0
Using selenium-webdriver 4.0.3
Using semantic_range 3.0.0
Using spring 3.0.0
Using sqlite3 1.4.2
Using turbolinks-source 5.2.0
Using turbolinks 5.2.1
Using web-console 4.1.0
Using webdrivers 5.0.0
Using webpacker 5.4.3
Bundle complete! 17 Gemfile dependencies, 76 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
       rails  webpacker:install
rails aborted!

Followed by this error:

LoadError: cannot load such file -- nokogiri/nokogiri
Caused by:
LoadError: dlopen(/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/2.6/nokogiri.bundle, 0x0009): could not use '/Library/Ruby/Gems/2.6.0/gems/nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/2.6/nokogiri.bundle' because it is not a compatible arch - /Library/Ruby/Gems/2.6.0/gems/nokogiri-1.12.5-x86_64-darwin/lib/nokogiri/2.6/nokogiri.bundle

I'm using Rbenv, which has the correct path and get's an ok from the doctor script.

If I do the following in terminal I get: ruby -v ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin20] rails -v Rails 6.1.4.1 which rails /usr/local/bin/rails

There's a default ruby version that comes with Macs, it seems to be trying to use this during rails new. I can't figure this out.

Lowlife answered 2/11, 2021 at 8:13 Comment(0)
L
23

Well, it's trying with Using nokogiri 1.12.5 (x86_64-darwin) which is for x86 processors, but you'll need the arm64-darwin version. I have no M1 machines to try it out, but you might try reinstalling Nokogiri with:

gem uninstall nokogiri
bundle config set force_ruby_platform true
bundle install
Lour answered 2/11, 2021 at 23:20 Comment(4)
Thanks for the suggestion, among many other google'd things I gave this a go an eventually rails completed the process. Thank-you for your suggestion.Lowlife
Had the above issue on xcode when running pod install with the following error: Error loading the plugin slather-2.7.2. LoadError - cannot load such file -- nokogiri/nokogiri This solved it. ThanksInflight
This worked for me when setting up a new docker container. However I had to use the -I flag to force gem uninstall to ignore the fact that the gem was a required dependency for other gems. RUN gem uninstall nokogiri -IKramlich
does it prevent adding arch64 etc to Gemfile.lock ? I'd like to avoid it since on localhost I use mac m1 and production is linuxDisintegration
C
5

In case someone faces this issue and the bundle config set force_ruby_platform true solve didn't fix it:

NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri

or if you prefer a bundle-based solution

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

I guess it may happen on setups where you have played around with the x86_64 approach and you are now trying to use the native arm64 one.

Crassus answered 7/10, 2023 at 1:4 Comment(0)
S
-1
  1. Uninstall nokogiri
  2. Install nokogiri unsupported version via gem installation
gem install nokogiri -v "VERSION"

Then bundle will take this specific version

  1. For all incompatible gems ,follow the same steps as 3.
Spinney answered 7/7, 2022 at 14:17 Comment(0)
P
-6

It's not about Nokogiri. It's about Jekyll on Apple M1:

Useful link: https://www.earthinversion.com/blogging/how-to-install-jekyll-on-appple-m1-macbook/

Pirtle answered 12/9, 2022 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.