How to Install ffi on Apple Silicon M1 in Native Mode Without Rosetta


Have you been struggling to install ffi on your M1 Mac? Have you been seeing these common errors:

Or an error like this?

[capacitor] /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require’: 
dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle, 0x0009): tried: 
(mach-o file, but is an incompatible architecture (have ‘arm64’, need ‘x86_64’)), 
‘/usr/lib/ffi_c.bundle’ (no such file) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/lib/ffi_c.bundle (LoadError)

You’ve probably been seeing these ffi issues while trying to get cocoapods, Capacitor, Slate, or sassc to work. Or maybe some other tool that depends on ffi.

Unfortunately, there’s a lot of outdated and incorrect advice out there, which causes people to mess up their development environment.

The 4 main reasons people struggle to install ffi on their M1 Mac

1) They don’t have a proper Ruby development environment, and they’re trying to install gems using the system Ruby. Learn why you shouldn’t use the system Ruby to install gems on a Mac.

2) They’re trying to install an older version. If you’re trying to install ffi as part of a Ruby project with a Gemfile, try running bundle update ffi to get the latest version.

3) They followed outdated advice to use arch -x86_64 or run terminal in Rosetta mode.

4) They followed bad advice to use sudo. Learn why you should never use sudo to install gems.

So how can you get a proper Ruby development environment so you can finally install ffi?

How to install ffi on Apple Silicon M1 in native mode

The key to a proper Ruby development environment is to install a separate and newer version of Ruby with a version manager. At a high level, it involves these 5 steps:

  1. Install Homebrew (which also installs the prerequisite Apple command line tools, also known as the Xcode command line tools)
  2. Install a Ruby manager
  3. Configure the Ruby manager
  4. Install a specific version of Ruby
  5. Switch to that version of Ruby

While you could spend the time setting everything up manually, there’s a better way! To save people frustration, and hours of their precious time, I built Ruby on Mac, an automated script to help people like you get a proper Ruby setup. I guarantee it will fix your ffi issues or I will personally fix it for you.

Here’s a review from someone who had ffi issues:

You (and your wonderful script) saved me from great peril today. I had developed my first Jekyll site some months ago. And I am now in the middle of developing a site using Eleventy. Earlier today, I went back to my Jekyll site to make sure that I could still build it as I had some updates to make. Sadly, the site failed to build with the horrendous “ffi” error that is going around. After numerous ill-fated attempts to get it working, trying every workaround that I could find, I ultimately came across your script. While it does take some time to get through it, I have to say that it has worked wonderfully! My site builds once again and I feel like the ruby platform that your script placed on my system is far less fragile than before. Thank you again for the great script and your service to the community. - Bob Mansour

Read more reviews from customers who love Ruby on Mac.

It doesn’t just have a one-time use. You can run it over and over to keep your system up to date and secure. And the next time you get a new Mac, it will save you half a day because it can also automatically install all your Mac apps, in addition to a complete development environment. You get all of these time savings now and in the future for a one-time cost.

When you buy Ruby on Mac today, you’ll be supporting an independent developer, and you get it at a very reasonable price given how much time it saves.

If you’re trying to set up ffi on a work computer, you should be able to expense the one-time cost of Ruby on Mac.