How To Install Homebrew, Ruby, Rails, Jekyll On A Mac With The M1 (Apple Silicon) Chip

Instead of boring you with the background history that I was starting to write, I realized it can all be summarized to these 3 points:

Homebrew installs things in a different directory when in native mode (/opt/homebrew) versus /usr/local in Rosetta mode (or when using the arch -x86_64 flag). So, it's easy to get confused and run into issues if you launched Terminal in native mode but started running some commands with arch -x86_64 and others without. Or if you launched Terminal in Rosetta mode and then tried to work with things that expected native mode.

When you use my script, you don't have to worry about any of this.

Although it can detect which mode you're in and install Homebrew and other tools in the appropriate places, I recommend doing everything in native mode since it's fully supported now. I've been using Jekyll and Rails without any issues on my M1 MacBook Air. My script also automatically installs Jekyll and Rails for you.

One issue you might run into if you have an existing Ruby project with an older version of the ffi gem, is an error saying failed to load command and then a more specific error like this one:

~/.gem/ruby/2.7.2/gems/ffi-1.13.1/lib/ffi/types.rb:69:in `find_type': 
unable to resolve type 'size_t' (TypeError)

The solution is simple:

bundle update ffi

For Rails and Jekyll projects, you might need to update both ffi and sassc:

bundle update ffi sassc

If you see other unexpected errors that point to a particular gem, the first thing I would try is to update that gem.