Install Ruby on Apple silicon

November 27, 2020

If you’ve recently bought an Apple silicion device you may been wondering how you can install Ruby. You can install Ruby natively, but some native gems may not have support for ARM64.

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 rbenv.

Steps to install Ruby on M1 using Rosetta 2

  1. Download and install rbenv natively
  2. Download and install ruby-installer natively
  3. Build the latest verison of Ruby, at the time of this blog it was 2.7.1, but any version should work.
  4. Install using the arch command

     arch -x86_64 /bin/bash -c 'rbenv install 2.7.1' 
    
  5. 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.

Ruby installed on arm

As you can see I have Ruby running on my M1 machine!

All gems (even with native extensions) seem to work so far.

If you want to install ruby natively, you can simply omit the arch flag, on Apple silicon this will default to aarch64.

Back to top