How to Configure your Mac M1 for Ruby on Rails development?

alt text A nicer picture of my new Mac Mini. Photo by Quinton Coetzee on Unsplash

Recently I bought a Mac mini with 16GB of RAM. I’m pleased with the machine, but I had initial issues setting up everything. This blog post should help you get setup. The solution is so simple. Scroll down if you are in a hurry.

Background

Here are some stack traces I encountered while installing rbenv:

-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.2.tar.bz2
Installing ruby-2.7.2...
ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201221)

Inspect or clean up the working tree at /var/folders/z1/dm8dx54j1dlgxk4zrq__x22r0000gn/T/ruby-build.20201221160748.90156.i6p4m0
Results logged to /var/folders/z1/dm8dx54j1dlgxk4zrq__x22r0000gn/T/ruby-build.20201221160748.90156.log

Last 10 log lines:
installing default nkf libraries
compiling date_strftime.c
installing default console libraries
linking shared-object objspace.bundle
compiling date_strptime.c
linking shared-object io/nonblock.bundle
linking shared-object io/console.bundle
linking shared-object nkf.bundle
linking shared-object date_core.bundle
make: *** [build-ext](#) Error 2

Here is what happened when I tried to install the ruby-idn gem:

ERROR: could not find idn library!

And here is an example of what happened with the ffi ruby gem

ruby-build: using readline from homebrew

BUILD FAILED (macOS 11.1 using ruby-build 20201210-10-g5de6d5f)

Inspect or clean up the working tree at /var/folders/mz/q1f7_y852v7__rt9f3lm0yd40000gn/T/ruby-build.20201229181439.24184.CZQlN7
Results logged to /var/folders/mz/q1f7_y852v7__rt9f3lm0yd40000gn/T/ruby-build.20201229181439.24184.log

Last 10 log lines:
compiling fiber.c
linking shared-object fiber.bundle
compiling closure.c
closure.c:263:14: error: implicit declaration of function 'ffi_prep_closure' is invalid in C99 [-Werror,-Wimplicit-function-declaration](#)
result = ffi_prep_closure(pcl, cif, callback, (void *)self);
 ^
1 error generated.
make[2](#): *** [closure.o](#) Error 1
make[1](#): *** [ext/fiddle/all](#) Error 2
make: *** [build-ext](#) Error 2

I also encountered this error with the http-parser gem.

Could not open library '/Users/---/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle': dlopen(/Users/---/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle, 5): no suitable image found.  Did find: (LoadError)
/Users/---/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle: mach-o, but wrong architecture
/Users/---/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/http-parser-1.2.2/ext/aarch64-darwin/libhttp-parser-ext.bundle: stat() failed with errno=25

I don’t use Docker and don’t want to run a VM. For anyone in the throes of random errors and getting frustrated, I’m hoping this blog post finds you.

I was also encountering issues with different homebrew formulas such libffi.

Solution

In the end, it was pretty easy but it’s not an ideal solution.

  1. Go to your Applications folder and copy the Terminal app (or iTerm)
  2. Rename it to Terminal Rosetta
  3. Right-click on the Terminal > Get Info > Make sure “Open in Rosetta” is checked.
  4. Close apps and Reopen.

alt text

You should now be ready to go. Open your renamed Terminal, and everything will magically work. Your Terminal is running in Rosetta, which acts as a translation between Apple Silicon and Intel-based chips

Purists argue that this isn’t fixing the problem and what’s the point of running your apps in Rosetta mode. To me, I can say one thing:

“My bills gotta get paid”

In time, I imagine you will be able to work as normal on the Arm architecture but in the meantime, this is a possible workaround.

© 2021 William Kennedy, Inc. All rights reserved.