Skip to content

Addressing nio4r Installation Errors on macOS Sonoma (M series) ​

When setting up Ruby projects on new Apple Silicon Macs (M1/M2/M3) running macOS Sonoma, developers often encounter a problematic installation error related to the nio4r gem:

terminal
An error occurred while installing nio4r (2.5.8), and Bundler cannot continue.
...
selector.c:301:26: error: incompatible function pointer types [-Wincompatible-function-pointer-types]

This occurs because newer Clang compilers on macOS Sonoma enforce stricter type checks during native extension builds. The nio4r gem (v2.5.8) contains type mismatches that were previously ignored.

Verified Solutions ​

The nio4r project fixed this issue in version 2.5.9. To implement this solution:

  1. Update your Gemfile specification:
ruby
gem 'nio4r', '>= 2.5.9'
  1. Update dependencies:
bash
bundle update nio4r

2. Apply Compiler Flag Workaround (Forced Version Constraint) ​

If you require specifically nio4r v2.5.8, suppress the warning during compilation:

TIP

This works for both gem install and bundle install

bash
# For system-level gem installations
gem install nio4r -v '2.5.8' -- --with-cflags="-Wno-incompatible-function-pointer-types"

# For project bundle installations
bundle config build.nio4r --with-cflags="-Wno-incompatible-function-pointer-types"
bundle install

Key Notes ​

  • This error is specific to Apple Silicon architecture (arm64-darwin)
  • Ruby version managers like asdf or rbenv require rebuilding Ruby with ARM-support
  • Similar errors with pg, msgpack, or jaro_winkler can be resolved with the same CFLAG pattern

Final Recommendation ​

Always prefer upgrading to nio4r >=2.5.9 where possible. The compiler flag workaround should only be used temporarily until dependencies can be updated. Most Rails applications safely support this gem version bump without compatibility issues.