Isolated Ubuntu VM on Mac with Lima: Step-by-Step Setup Guide (Apple Silicon)
Home / Blog / Development

Isolated Ubuntu VM on Mac with Lima: Step-by-Step Setup Guide (Apple Silicon)

Run Ubuntu 24.04 without cluttering your Mac: isolated VM setup with Lima, a correct YAML configuration, start and stop commands, an Nginx test, and an SSH tunnel.

On this page 0

    When you want to try new software, run an unfamiliar script, or learn Linux, you probably do not want to risk your Mac's main system. The answer is a lightweight Linux virtual machine that runs separately from macOS. Lima is an open-source tool that helps you create Linux virtual machines on macOS from the terminal. In this guide, we show how to set up an isolated Ubuntu 24.04 virtual machine with Lima on an Apple Silicon Mac (M1, M2, M3, M4), start and stop it, run Nginx inside it, and transfer files. We also share a real mistake made during the setup and how it was fixed.

    1What Is Lima, and Why Use It?

    Lima is a command-line tool that runs Linux virtual machines on macOS. On Apple Silicon Macs it can use Apple's native virtualization layer (vz, or Virtualization.framework), which keeps it lightweight and fast. Because it focuses on the terminal rather than a graphical interface, it is a practical option for developers and Linux learners.

    • Keeps your Mac clean: Packages, services, and experiments stay inside the virtual machine.
    • Easy to delete: If you break the system, you can remove it and start over with one command.
    • Managed with a config file: A single YAML file makes the setup repeatable.
    • Isolation is configurable: You can disable Mac folder mounts and port forwarding.
    The purpose of an isolated virtual machine is to experiment safely and start from scratch with one command if something goes wrong.

    2What You Need Before You Start

    • A Mac running macOS (this guide was tested on Apple Silicon).
    • The Homebrew package manager.
    • About 5-6 GB of free disk space (more is better, since the virtual disk can grow up to 20 GB).
    • An internet connection (the Ubuntu image is about 590 MB).

    3Install Lima and Clean Up Old Leftovers

    Open Terminal and install or update Lima with Homebrew:

    brew install lima
    brew upgrade lima
    limactl --version

    If you made a failed attempt earlier, clean up the leftovers:

    limactl delete -f izole-ubuntu 2>/dev/null
    rm -f ~/lima.REJECTED.yaml ~/izole-linux.yaml

    This step helps prevent problems caused by locked files or old configuration from an unfinished setup.

    4Create the Correct YAML Configuration File

    Lima creates the virtual machine from a YAML file. The configuration below uses the Ubuntu 24.04 cloud image, does not mount Mac folders, and disables automatic port forwarding:

    cat << 'EOF' > ~/izole-linux.yaml
    vmType: "vz"
    
    images:
      - location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-arm64.img"
        arch: "aarch64"
      - location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img"
        arch: "x86_64"
    
    cpus: 2
    memory: "2GiB"
    disk: "20GiB"
    
    # Isolation: Mac folders are not mounted
    mounts: []
    
    # Isolation: automatic port forwarding is disabled
    portForwards:
      - guestPortRange: [1, 65535]
        ignore: true
    
    containerd:
      system: false
      user: false
    EOF

    What the key fields mean:

    • vmType: "vz": Uses macOS's native virtualization layer.
    • images: Selects the right Ubuntu cloud image for your processor architecture. Lima uses the matching one automatically.
    • cpus, memory, disk: The resources assigned to the virtual machine.
    • mounts: []: Prevents the virtual machine from accessing your Mac files.
    • portForwards: Stops services in the virtual machine from being exposed on Mac ports automatically.

    5Create and Start the Virtual Machine

    limactl start --name=izole-ubuntu --tty=false ~/izole-linux.yaml

    The --tty=false flag skips the interactive menu and starts the setup directly. On the first run, the image is downloaded and converted to a disk; then the log shows a line like this:

    READY. Run `limactl shell izole-ubuntu` to open the shell.

    To check the status:

    limactl list

    The izole-ubuntu row should show Running.

    In the setup behind this guide, the first attempt failed. The cause was that the location field in the YAML file contained the https://ubuntu.com homepage instead of an image. Lima downloaded only a web page of about 184 KiB and the virtual machine stopped immediately; the log showed vm state change: stopped.

    • If the download size is in KiB, the image is wrong. The real Ubuntu image is about 590 MiB.
    • The location field must point directly to an .img image file.
    • After a failed attempt, delete the lima.REJECTED.yaml file and the broken machine, then start again.

    7Enter the Virtual Machine and Verify It

    limactl shell izole-ubuntu

    If your prompt changes to something like mertali@lima-izole-ubuntu:~$, you are no longer on your Mac but inside the virtual machine. Run these commands to verify:

    cat /etc/os-release | head -n 4
    uname -m
    mount | grep -i virtiofs || echo "Mac folder is not mounted"
    • The first command should show Ubuntu 24.04 information.
    • uname -m should return aarch64 on Apple Silicon.
    • The third command should print “Mac folder is not mounted”.

    First, update the system:

    sudo apt update && sudo apt upgrade -y

    8Start, Stop, and Delete the Virtual Machine

    All of these commands run from the Mac terminal:

    # Start
    limactl start izole-ubuntu
    
    # Check status
    limactl list
    
    # Open a shell
    limactl shell izole-ubuntu
    
    # Leave the VM (it keeps running)
    exit
    
    # Stop gracefully
    limactl stop izole-ubuntu
    
    # Force stop if it hangs
    limactl stop -f izole-ubuntu
    
    # Delete completely
    limactl delete -f izole-ubuntu
    • exit only leaves the session; the virtual machine keeps running in the background and using RAM.
    • When you are done, shut it down with limactl stop.
    • If you restart your Mac, the virtual machine stays off; run limactl start to continue where you left off.

    9First Project: Run a Website with Nginx

    While inside the virtual machine, install Nginx and create a simple page:

    sudo apt install -y nginx
    sudo systemctl enable --now nginx
    systemctl status nginx --no-pager
    
    echo '<h1>Hello Lima!</h1>' | sudo tee /var/www/html/index.html
    curl http://localhost

    If the curl output shows your heading, Nginx is working. Because port forwarding is disabled, you cannot open this site directly from your Mac browser; use the method in the next section.

    10View It in Your Browser Without Breaking Isolation: SSH Tunnel

    Instead of enabling port forwarding, you can open a temporary SSH tunnel. Open a new terminal tab on your Mac:

    ssh -F ~/.lima/izole-ubuntu/ssh.config -L 8080:localhost:80 lima-izole-ubuntu

    Then visit http://localhost:8080 in your browser. To close the tunnel, type exit in that terminal. This way, the virtual machine does not need to be permanently exposed to your Mac.

    11Transfer Files Between Your Mac and the Virtual Machine

    Since Mac folders are not mounted, you move files with limactl copy:

    # From Mac to the virtual machine
    limactl copy file.txt izole-ubuntu:~/
    
    # From the virtual machine to Mac
    limactl copy izole-ubuntu:~/file.txt ~/Desktop/

    This approach makes every transfer a deliberate and controlled action.

    12Back Up Your VM and Know the Limits of Isolation

    Before a risky experiment, you can make a copy of the virtual machine:

    limactl stop izole-ubuntu
    limactl clone izole-ubuntu backup-ubuntu
    limactl start izole-ubuntu

    It is important to be realistic about isolation:

    • This setup does not mount Mac folders and disables automatic port forwarding, which provides a strong separation for everyday experiments.
    • Lima may keep some default behaviors. For example, startup logs may show UDP 5353 forwarding for mDNS.
    • Isolation is not absolute. For truly dangerous tasks such as malware analysis, take additional precautions and consult specialist resources.
    • The virtual machine can reach the internet; the security of the software you install inside it is your responsibility.

    ?Frequently Asked Questions

    What is Lima?

    Lima is an open-source tool that creates and manages Linux virtual machines on macOS from the command line. The configuration is defined in a YAML file and the machines are managed with the limactl command.

    Does Lima work on Intel Macs too?

    Yes, the x86_64 image line in the configuration is there for that purpose. This guide was tested on Apple Silicon; on Intel Macs, check version and vmType support first.

    Why did the downloaded image only come to a few hundred KiB?

    Most likely the location field contained a web page address instead of an image. The correct Ubuntu cloud image is about 590 MiB and the link must point to an .img file.

    Can the virtual machine access my Mac files?

    Not with this configuration. The mounts: [] setting prevents Mac folders from being mounted. Use limactl copy to move files.

    How do I delete the virtual machine completely?

    Stop it if needed, then run limactl delete -f izole-ubuntu. If your YAML file is still there, you can rebuild the same setup in minutes.

    What happens if I do not shut the virtual machine down?

    exit only closes the session; the virtual machine keeps running and using RAM. When you finish, shut it down with limactl stop izole-ubuntu.

    How do I view my website in the Mac browser?

    Instead of enabling port forwarding, you can use an SSH tunnel. While the tunnel is open, port 80 in the virtual machine is reachable on your Mac at localhost:8080.

    ✦Conclusion

    With Lima, you get an isolated, easy-to-delete, repeatable Ubuntu environment inside your Mac. Use the correct image link, verify the setup with limactl list, stop the machine when you are done, and take a backup before risky experiments. If you work with an awareness of isolation limits, this setup becomes a practical lab for learning Linux, testing web servers, and trying new tools safely. Create your YAML file now and start your first virtual machine.

    Share
    ← Previous
    What Is Warp Terminal? Setup, Blocks, Warp Drive, and AI Features Guide for macOS
    Next →
    Local SEO Guide: How to Reach Nearby Customers on Google

    Related Articles

    What Is Warp Terminal? Setup, Blocks, Warp Drive, and AI Features Guide for macOS
    Development
    What Is Warp Terminal? Setup, Blocks, Warp Drive, and AI Features Guide for macOS

    What is Warp terminal, how do you install it, and what do Blocks and Warp Drive do? A step-by-step guide to its AI features, privacy settings, and using it with Lima.

    Corporate Website Design: A Guide to Building Trust and Winning Customers
    Web Design & Digital Strategy
    Corporate Website Design: A Guide to Building Trust and Winning Customers

    Build a stronger corporate website with a practical guide to brand identity, user experience, mobile design, content, SEO, accessibility, and conversion-focused design.

    SEO Optimization
    Digital Strategy
    SEO Optimization

    Improve your website’s discoverability with SEO optimization. Explore practical steps for content, technical foundations, page experience, and performance measurement.