Notes
Install Ruby with rbenv and CocoaPods on M1 MacBook (Apple Silicon)
installing Ruby with rbenv via Homebrew and then CocoaPods on an M1 MacBook, including the ffi gem and rbenv rehash
iOS
2 minutes
Doing your own Ruby installation instead of using the system one is preferred, either with Homebrew or rbenv. Apple is deprectaing the default system installation of Ruby anyway.
Homebrew, rbenv and Ruby
1# install homebrew
2/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3
4# install ruby with rbenv
5brew install rbenv # ruby-build is included
6rbenv install 3.0.1
7rbenv global 3.0.1 # set system default ruby version
8
9ruby -v
10# ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [arm64-darwin20]
1rbenv install -l # list versions that can be installed
2rbenv versions # list installed ruby versions
3rbenv global 3.0.1 # set system default ruby version
Cocoapods
1gem install ffi cocoapods
2rbenv rehash # run a rehash after installing gems (or a new Ruby version) to make sure everything new is on your PATH:
sudois not needed for Ruby versions installed withrbenvffiis needed here to get rid of some ffi related LoadErrorrbenv rehashis important, otherwise the Podfile will keep using the old system installed Ruby
Now you can go to your iOS project and do pod repo update && pod install
Troubleshooting
- if you’re getting errors about versions not found or mismatched versions..
1rm -rf ./Podfile.lock
- if you have a real old project and the an old install of CocoaPods, you can delete the CocoaPods repo cache and update it again
1sudo rm -rf ~/.cocoapods/repos
2pod repo update
- i was getting the following error when doing a
pod installinside an iOS project with Ruby installed with Homebrew and an old CocoaPods installation. The issue is not with FFI library and the error went away with this fresh install of Ruby and CocoaPods
LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle, 0x0009): missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle - /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/lib/ffi_c.bundle