A Rubyist's Apple M1 Review

Episode #270 by Teacher's Avatar David Kimura

Summary

A broad look into the Apple M1 from the perspective of a Ruby Developer. We look at a lot of the different aspects; Docker, asdf Ruby, Visual Studio Code, and more.
development rails 12:35

Resources

UPDATE Feb 2021: I've been using the M1 with Docker successfully and it has been a great experience. At this point I would probably hold off until their next version as it will likely be much faster. However, if you're in a pinch and need something now. A 16GB RAM version would be the way to go. I've head of many who got the 8GB version and wish they had gone with 16GB. You can get started with Docker on the M1 at https://docs.docker.com/docker-for-mac/apple-m1/

UPDATE April 2021: I've been using HomeBrew without specifying the x86 Arch for some time now and it's been very stable. 

Summary

Homebrew


arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Oh My ZSH


sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
compaudit | xargs chmod g-w,o-w

# Add to ~/.zshrc
alias a="arch -x86_64"
alias ibrew="arch -x86_64 brew"

Other Applications


brew cask install iterm2
ibrew install node
npm -g install yarn
ibrew install postgresql
ibrew install redis

Docker


arch -x86_64 brew install docker
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa USERNAME@IP_ADDRESS
docker run -p 80:80 nginx

asdf


ibrew install asdf
echo ". $(brew --prefix asdf)/asdf.sh" >> ~/.zshrc
source ~/.zshrc
asdf plugin-add ruby https://github.com/asdf-vm/asdf-ruby.git
a asdf install ruby 2.7.2
asdf global ruby 2.7.2

Other


echo 'gem: --no-document' >> ~/.gemrc

Rails


gem install rails
rails new template
rails db:system:change --to=postgresql


Update


I've been testing things further with an alternative method of Homebrew installation. This will allow for packages to be installed to the arm64 instead of forcing them through Rosetta2. The benefit of this is that libraries like RVM and asdf will use Homebrew to install dependencies. Now, with the dependencies being installed for arm64 instead of Rosetta2, we can install and compile Ruby for arm.

Install Homebrew


xcode-select --install
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv homebrew /opt/homebrew
cd /opt/homebrew/bin
./brew update
echo "export PATH="/opt/homebrew/bin:$PATH"" >> ~/.zshrc
source ~/.zshrc

IMPORTANT NOTE


If you're now having issues with brew installs, you can try to add the -s flag which will download from source even if a package is available.

brew install -s PROGRAM_NAME

If you're going to be using Ruby on Rails, there is an issue with the FFI library where you will need to pull from master. This is accurate for the 1.13.1 version of FFI. You can add this to the Gemfile

gem 'ffi', github: 'ffi/ffi'

# or 

gem 'ffi', git: 'https://github.com/ffi/ffi.git'

You'll need to install node from source.

brew install wget
wget https://nodejs.org/download/release/latest/node-v15.3.0.tar.gz
tar zxf node-v15.3.0.tar.gz
cd node-v15.3.0
./configure; make
sudo make install

sudo npm -g install yarn

Install RVM (or asdf) and Ruby


\curl -sSL https://get.rvm.io | bash -s stable
source $HOME/.rvm/scripts/rvm
rvm install 2.7.2

Check it Out
➜  ~ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

The results are amazing. HOWEVER, I just cannot recommend this approach at this moment until things get ironed out. There are still too many issues and compatibility problems with the Ruby ARM Version. I've found a few crashes and it's just not stable enough. For now, continue to use the Ruby x86 version.