Lima VM - Linux Virtual Machines On macOS
We’re Earthly. We simplify building software using containerization. If you’re setting up Linux VMs on macOS with Lima, Earthly you might like Earthly’s approach to containerized Linux builds. Check it out.
WSL2 for macOS
I like my mac book pro. It’s not an M1, just a 2019 X86 MacBook. But it’s Unix based and POSIX compliant. One thing though, it’s certainly not Linux. If I want a Linux environment on my laptop, I need a VM.
Lima (LInux MAchine) is the simplest way I know of to get that virtual machine. Once it’s setup you just type lima
in a terminal window to be placed in a Linux VM but with all your files and ports available. It’s like WSL2 but for macOS.
How It Works
Lima is powered by QEMU and is frequently used (via colima) to run containers on macOS. That is, it can be used as an alternative to docker desktop.
Ubuntu Setup
Let’s install it.
> brew install lima
Check your version:
> limactl --version
I’m going to install an ubuntu-lts. LTS stands for long term support meaning that there is a longer term commitment to update, patch, and maintain the software.
To see all the possible lima VM templates use `--list-templates
:
> limactl start --list-templates
almalinux
alpine
archlinux
buildkit
centos-stream
debian
default
deprecated/centos-7
docker-rootful
docker
experimental/9p
experimental/almalinux-9
experimental/apptainer
experimental/centos-stream-9
experimental/opensuse-tumbleweed
experimental/oraclelinux-9
experimental/riscv64
experimental/rocky-9
faasd
fedora
k3s
k8s
nomad
opensuse
oraclelinux
podman
rocky
singularity
ubuntu-lts
ubuntu
vmnet
To setup my first VM I use start:
> limactl start --name=default template://ubuntu-lts
Which installs lts with name default
.
After that I can jump into my linux shell by typing lima
:
> uname
Darwin
> lima
> uname
Linux
And much like WSL2 on Windows, I have access to all my macOS files within Lima. One difference, however, is that I can not write to these files.
> lima
> touch file.txt
touch: cannot touch 'file.txt': Read-only file system
But by default at least, I can write to files under /tmp/lima
:
> lima
> cd /tmp/lima/
> touch lima.txt
All of this is configured in the VM template. The Ubuntu-lts templates specifies these like this:
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true
Writable Ubuntu Setup
It’s possible to set a folder writeable, and it looks like Rancher (which uses lima under the covers on macOS) uses this configuration so let me try it.
First I stop lima:
> limactl stop default
Then I edit it:
> limactl edit default
I only need access to my sandbox
folder, where I keep all git repos, so I’ll edit things to only mount that, but mount it as writable.
mounts:
- location: "~/sandbox"
writable: true
Then I can start the VM back up( limactl start default
) and lima
into it and write and edit files all I want.
> lima
> echo "hello" > file.txt
> cat file.txt
hello
It should be noted that lima itself suggests a writable mount like this could be dangerous, but everyone is doing it.:
# CAUTION: `writable` SHOULD be false for the home directory.
# Setting `writable` to true is possible, but untested and dangerous.
Conclusion
Lima seems to be a solid choice for a Linux terminal environment on MacOS. Some users have reported slow file system performance, but in my experience, using it in a limited capacity, I haven’t encountered such issues. And if you’re loving your new Linux set-up on macOS with Lima, consider leveling it up with Earthly for a smooth, efficient build process. It’s definitely worth checking out!
Earthly makes CI/CD super simple
Fast, repeatable CI/CD with an instantly familiar syntax – like Dockerfile and Makefile had a baby.