### TL;DR:
- Install your own version of Ruby with Homebrew / rbenv / RVM (e.g. `brew install ruby`)
- Add it and the gems binaries to your `PATH` and make sure the new version is used with `which ruby` (should be `/opt/homebrew/opt/ruby/bin/ruby` instead of `/usr/bin/ruby` if installed with Homebrew)
- Install CocoaPods with `sudo gem install cocoapods` (make sure `ethon` is at least version 0.13.0)
- Run `pod install`
### Detailed answer:
All answers suggesting using Rosetta / `arch -x86_64` are workarounds and not quite solving the real issue that comes from the way RbConfig and the universal binaries work.
```rb
require 'rbconfig'
OSVERSION = RbConfig::CONFIG['host_os']
ARCH = RbConfig::CONFIG['arch']
HOSTCPU = RbConfig::CONFIG['host_cpu']
BUILDCPU = RbConfig::CONFIG['build_cpu']
TARGETCPU = RbConfig::CONFIG['target_cpu']
puts "OS: #{OSVERSION}"
puts "Arch: #{ARCH}"
puts "Host CPU: #{HOSTCPU}"
puts "Build CPU: #{BUILDCPU}"
puts "Target CPU: #{TARGETCPU}"
```
If you call `ruby` on a file containing this code with the universal binary shipped with macOS, you will get the following result on an M1 Mac:
```
OS: darwin20
Arch: universal-darwin20
Host CPU: x86_64
Build CPU: x86_64
Target CPU: universal
```
As you can see, RbConfig was compiled for a « universal » CPU but built with an x86 CPU, and the `rbconfig.rb` file that was generated (see `/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb`) consequently uses invalid information for the host CPU.
As `ffi` uses information from RbConfig (see
[To see links please register here]
and
[To see links please register here]
), we end up with OP’s error message.
The solution is, therefore, to get a version of Ruby built specifically for arm64 by using either Homebrew, rbenv or RVM.
For Homebrew:
- Execute `brew install ruby`
- Add `export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH` to your `.zshrc` (you can find your Homebrew installation directory with `$(brew --prefix)` if needed)
- Execute `source ~/.zshrc` or restart your shell
- Make sure you are using the correct `ruby` binary by executing `which ruby` (should be `$(brew --prefix)/opt/ruby/bin/ruby`)
- Install CocoaPods with `sudo gem install cocoapods`
- Make sure you are using the correct `pod` binary by executing `which pod` (should be `$(brew --prefix)/lib/ruby/gems/3.0.0/bin/pod`)
- Make sure `ethon` is version 0.13.0 or more with `gem info ethon`, otherwise run `sudo gem install ethon`
- Run `pod install`
### Ruby won't come with future macOS versions by default
Moreover, it should be noted that `ruby` is still included in macOS only « for compatibility with legacy software », as evidenced by running `irb -v`, so this is probably a good opportunity to install your own version anyway:
> WARNING: This version of ruby is included in macOS for compatibility
> with legacy software. In future versions of macOS the ruby runtime
> will not be available by default and may require you to install an
> additional package.
>
> irb 1.0.0 (2018-12-18)
Sources:
-
[To see links please register here]
-
[To see links please register here]