Notes

Install Ruby with rbenv and CocoaPods on M1 MacBook (Apple Silicon)

Edit on GitHub

iOS
2 minutes
  1. install Homebrew
  2. Install Ruby with rbenv
  3. Install CocoaPods

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:
  • sudo is not needed for Ruby versions installed with rbenv
  • ffi is needed here to get rid of some ffi related LoadError
  • rbenv rehash is 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 install inside 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