Install Singularity on Apple Silicon Chips

Written by Alex McCreight, September 2023

IMPORTANT: Your macOS version MUST be 13.0+

Step 1

Install iTerm2, homebrew, micromamba, SoS, docker, and colima, and set up your virtual machine using these instructions. I recommend following all optional steps.

Step 2

Install Rosetta. Go to your terminal and copy and paste the following:

softwareupdate --install-rosetta

Step 3

Open your finder and locate your home directory (Cmd + Shift + H). From there you will need to show your hidden files (Cmd + Shift + .) and locate your .lima folder. Within this folder you should see the virtual machine you set up named apptainer-rootful, and within that folder you will need to add the following lines of code to the bottom of your lima.yaml file:

rosetta:
  enabled: true
  binfmt: true

Step 4

After you have edited your lima.yaml and saved the changes, you need to stop running your virtual machine.

limactl stop apptainer-rootful -f

Step 5

Now, you will need to recompile your lima.

brew uninstall colima && brew uninstall lima
brew install --build-from-source lima && brew install --build-from-source colima

Step 6

After the reinstallation, be sure to enter into a new terminal window. You can now launch your new VM.

limactl start Lima

Step 7

Once you have checked that your new VM properly runs, you will now return to your home directory (Cmd + Shift + H) and locate your .lima folder again. You should see a new folder called lima, and then within that folder, find the lima.yaml file and make the following edits to the mount section.

mounts:
  - location: "~"
    writable: true
  - location: "/tmp/lima"
    writable: true
mountType: "virtiofs"

Step 8

Once you have saved your changes to the lima.yaml file, create a script called singularity (without any file extension) and add the following to it.

#!/bin/bash
exec limactl shell Lima apptainer "$@"

Now, edit the following command to move your new script from its current location to usr/local/bin.

sudo mv ~/current-location/singularity /usr/local/bin/singularity

Once you have moved the script, you must make it executable by running the following command.

sudo chmod +x /usr/local/bin/singularity

Step 9

Now, enter back into your terminal and create the following alias for your new VM.

alias singularity = "liamctl shell Lima apptainer"

You now can easily access a list of available commands using: singularity -h

Troubleshooting

Error: Essential Requirement 1 of 3: “ssh”

When you start your VM and you see the message Essential Requirement 1 of 3: 'ssh' connected was refused or another variation of this message, multiple times without any change, follow these steps to resolve the issue:

First, you will need to run a factory reset on your VM.

limactl factory-reset Lima

Then, once your VM is reset, you will have to restart it.

limactl start Lima

Finally, you will need to rerun the final portion of step 8

sudo chmod +x /usr/local/bin/singularity

Should the error persist post these steps, consider revisiting the preceding setup steps or making a post on the Lima Github issues page for further assistance.