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.
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 `
> 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
After that I can jump into my linux shell by typing
> 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
> 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.
So far, lima seems pretty great for a linux terminal environment on MacOS. I found some complaints online of the file system being slow, but because of the limited way I’m using things I haven’t noticed that so far.
While you’re here:
Earthly is the effortless CI/CD framework.
Develop CI/CD pipelines locally and run them anywhere!