Apple Silicon is a new line of CPUs from Apple based on the ARM64 ISA. For the past decade (and longer!) we have been using x86_64, and nearly all software is compiled for x86.
As of 22nd December, 2020, ARM64 support has been merged into the OpenSSL tree. It is now possible to install Ruby natively, but for now I recommend using Rosetta 2. Just follow the installation instructions for
rbenv if you want to install it natively. Please see this PR for a discussion on ARM64 Ruby.
Apple have also developed Rosetta 2, a translation layer from x86 machine code to ARM64 machine code, it does by translating the assembly ahead of time, current estimates put it at ~65% of native x86 performance which is pretty outstanding for translating between two architectures. Obviously more IO intensive workloads may increase this percentage.
We can force Rosetta in the terminal by using the
arch -x86_64 flag with
Steps to install Ruby on M1 using Rosetta 2
- Download and install rbenv natively
- Download and install ruby-installer natively
- Build the latest verison of Ruby, at the time of this blog it was 2.7.1, but any version should work.
Install using the
arch -x86_64 /bin/bash -c 'rbenv install 2.7.1'
- Then run:
rbenv global 2.7.1
This sets Ruby 2.7.1 as the default Ruby version, obviously feel free to overwrite this for other projects.
As you can see I have Ruby running on my M1 machine!
All gems (even with native extensions) seem to work so far.
Another alterntive is to install Homebrew in Rosetta and then install Ruby, but most Rubyist will want to use
rbenv to manage their version of Ruby.
Next up is Rails!