3 Ways to Run Linux in macOS

If you’re a developer on a Mac, you might find yourself needing a real Linux environment. While macOS shares some similarities with Linux, it doesn’t always match the environments, the tools, or behavior of a true Linux system.

Running Linux on your Mac helps make your setup more like the servers where your apps or websites will eventually live, which means fewer surprises when you deploy your work.

In this article, we’ll explore three easy ways to bring Linux into your Mac workflow which can help you build, test, and experiment more efficiently right from your Mac.

Without further ado, let’s check it out.


1. Using Docker Container

Docker is a popular tool that brings containerization into your macOS. It allows you bundle your app and everything it needs like libraries and settings into something called a “container”. This container ensures your app runs the same way everywhere, whether it’s on your macOS or on a server.

Installation

To install Docker on your macOS, you’ll first need to make sure that system meets the basic requirements; you’ll need macOS 10.15 (Catalina) or newer, and at least 4 GB of RAM. Although I think it’ll be better to get 8 GB or more for the better performance.

Then, get the .dmg file from the Docker site. Be sure to choose the version that matches your Mac’s processor, Apple Silicon or Intel.

Once downloaded, open the .dmg file and follow the installation instruction.

After the installation is complete, you confirm everything is working by running the following command in Terminal:

docker --version

If you see a version number, you’re all set!

Docker version check in Terminal

Running a Linux Container

Let’s say you want to use Docker to run a Linux environment (like Ubuntu), and you also want the container to have access to a folder from your macOS, maybe to run files or apps.

You can do this by mounting a directory using the -v flag. For example:

docker run -it -v ~/Projects:/workspace ubuntu:latest /bin/bash

This command will first download the latest Ubuntu image (if you don’t already have it) and then start an interactive command line inside the container.

At this point, you are effectively “inside” a Linux environment, ready to type Linux commands.

Ubuntu Linux shell in Docker

Instead of using the latest tag, it is generally recommended to use a specific version of the image, like ubuntu:20.04, to ensure consistency in your environment. You can replace latest with any specific version you need, for example:

docker run -it -v ~/Sites/hkdc/ubuntu:/workspace ubuntu:20.04 /bin/bash

We can check the version and can confirm that we are now running Ubuntu version 20.04.

Ubuntu 20.04 running in Docker

Now, that we’ve run Linux using Docker, let’s see an alternative way.


2. Using OrbStack

OrbStack is a newer, faster alternative to Docker Desktop, made for macOS. Aside of a Docker container, OrbStack is also capable of running a lightweight virtual machine to run Linux.

Let’s see how this works.

Installation

First, we are going to install OrbStack.

The easiest and best way to install OrbStack on macOS is by using Homebrew Cask. You can open your Terminal app and type this command:

brew install --cask orbstack

Or, download the installer file from the website.

Running Linux VM

OrbStack support various Linux distros that you can run, including Ubuntu, Debian, OpenSuse, and even Arch.

To create these Linux virtual machines, you can open the OrbStack app, pick your favorite Linux version, and create a new machine using the visual interface.

OrbStack Linux VM installation interface

Or, you can do it automatically using the command line:

orb create ubuntu local-ubuntu-vm

This will create the VM with the latest Ubuntu version, in this case, it’s Plucky Puffin. It’s a non-LTS version, so you might want to use a specific version like 24.04 (Noble) or 22.04 (Jammy) instead.

To install specific version, for example 24.04 (Noble), you can use the following command:

orb create ubuntu:noble local-ubuntu-vm

OrbStack Commands

One of the things, that I like from VM in OrbStack is that it comes with the commands built in and integrated with the SSH configuration in your macOS. This means you can easily SSH into your VM without needing to set up anything else.

To SSH-in to the VM that we’ve just created, local-ubuntu-vm, you can simply run the following command in your Terminal:

ssh local-ubuntu-vm@orb

One my favourite is that OrbStack automatically mount your macOS directory in /mnt/mac, and already configured with proper permission, something that can be often a hassle in Docker.

OrbStack SSH terminal directory listing

Now, you can run any Linux commands, install packages, or even run your apps inside the VM.


3. Using LimaVM

Lima, which stands for “LInux MAchine”, provides a simple way to run lightweight Linux VM directly on your macOS.

Let’s see how to install it and how it works.

Installation

The easiest and most common way to install Lima on macOS is using Homebrew. You can open your Terminal and type this command:

brew install lima

Then, you can run the following command to check if it’s installed correctly:

limactl --version
// Or, just 
lima --version

Running up a Linux VM

Lima works with many different versions of Linux, letting you pick the environment that best fits what you need. To see a list of available options of the Linux distros you can run with Lima, you can use this command:

limactl start --list-templates

Lima supports various distros which includes Ubuntu, Debian, Fedora, and even Docker and Podman.

Lima VM Linux templates list

Let’s try starting an Ubuntu VM like in our previous examples, using the following command:

limactl start default

Once the VM installation is done, you can just run the following to SSH-in the VM:

lima
// Or
limactl shell default

Installing specific Ubuntu version

By default, Lima will create the VM with the latest LTS version of Ubuntu. If you want to install a specific version of Ubuntu, you can use the following command:

limactl start ubuntu-20.04 template://ubuntu-20.04

To SSH-in the ubuntu-20.04 VM, you can run:

limactl shell ubuntu-20.04

One thing that I like about Lima is that it automatically shares files between macOS and the Linux VM. This file sharing in Lima is also as fast as if it were in your macOS machine.

You can find your macOS home directory in /Users/<username> inside the VM.

Lima VM home directory contents
Listing the home directory in Lima VM

Wrapping up

Choosing the best way to run Linux on your Mac depends on what you need, how comfortable you are using the command line, and how powerful your Mac is.

Docker, OrbStack, and Lima each offer different benefits: Docker is great for running apps in containers, Lima is better for full Linux virtual machines, and OrbStack does both in a fast and efficient way. Instead of asking which one is better overall, think about which one suits your needs best.

So to help you decide, we’ve included a table that compares all three tools side by side, making it easier to see their pros and cons at a glance.

Feature Docker OrbStack Lima
Primary Use Case Containerization Lightweight Container/VM Full Linux VM
OS Supports Windows, macOS macOS Windows (untested), macOS, Linux
Filesystem Docker Volumes Shared Folders Shared Folders
GUI Yes Yes No (Only CLI)
Kubernetes Support Yes Yes (k3s) Yes (with templates k3s, k8s)
Cost Free with Paid for Commercial Use Free with Paid for Commercial Use Free
WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail