Development in Apple M1

eparreno

Emili Parreno

Posted on December 15, 2021

Development in Apple M1

I got a new laptop one week ago and I've been investigating different ways of setting up our dev environment. Here are my findings

Virtual Machines

There are different options

  • Virtual Box doesn't work as of today in Apple M1
  • Parallels, nice but you have to buy a license
  • UTM, very nice UI on top of QEMU. My preferred choice

If you run ARM virtual machines, it's fast as hell, feels like a native app, probably having a M1 Max with 10 cores and 64Gb of RAM helps bit :) but I wanted to use mainly x86 VMs and they are not so fast. I'll definitely use UTM in the future for running ARM based VMs.

Docker

If you run everything inside Docker, it works out of the box. I didn't experience any issues.

Apple's Rosetta

It turns out that the best virtualisation software comes already with you default MacOS installation and it's called Rosetta!

Here's how I set up my dev laptop

Duplicate your Terminal or iTerm app and give it a different name
Image description

I ended up with

Image description

In the x86 terminal, get info details (CMD + i) and check "Open using Rosetta"
Image description

That's it. Yes, really, that's all you need. Open your x86 terminal and you have an emulated x86 environment that just works.

If you install Hombrew in both envs it will be installed in different folders, the traditional /usr/local/Cellar for Intel based and the new one opt/hombrew/Cellar

I have a check in my .zshrc to load paths based on the arch. With that approach you need to be mindful about the arch you are running and loading the proper paths or executing the right code after login.

if [ $(arch) = 'arm64' ]; then
  ...
else
  ...
fi
Enter fullscreen mode Exit fullscreen mode

I also added $(arch) to my prompt to know in which environment I am

Image description

Caveats

If you install the same app or library in both environments they may clash. Let's say you install MySQL in both ARM and x86 using Homebrew and you want to link the binary, you should choose on what env you do it. Just be careful about that.
For me hasn't been a problem because I mainly use x86 so I didn't install anything in the ARM env. Just avoid installing the same stuff in both envs.
If you really need to use both arches, an alternative could be using Rosetta to emulate x86 and UTM to run ARM based VMs so you don't risk messing with duplicated libraries or apps.

💖 💪 🙅 🚩
eparreno
Emili Parreno

Posted on December 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Development in Apple M1
apple Development in Apple M1

December 15, 2021