DEV Community

Armando C. Santisbon
Armando C. Santisbon

Posted on • Updated on

Run an Ubuntu VM on Apple Silicon

VirtualBox does not support ARM-based architectures like the Apple silicon on these Macs yet so we'll need another option. Multipass from Canonical can launch and run virtual machines (instances) and configure them with cloud-init like a public cloud. In fact it's my preferred way to launch Ubuntu instances regardless of whether VirtualBox is available for my system.

Get it with Homebrew:

brew install multipass
Enter fullscreen mode Exit fullscreen mode

See the list of images available:

multipass find
Enter fullscreen mode Exit fullscreen mode

Useful commands when managing instances.
multipass help
multipass list
multipass start
multipass restart
multipass mount /Volumes/USB primary
multipass stop
multipass delete --all
multipass purge

We will:

  • Create an instance from the Ubuntu 22.04 LTS (Jammy Jellyfish) image.
  • Specify the number of CPUs, disk space, and amount of memory to allocate.
  • Give it a name. If the name is primary the user's home directory is mounted inside the newly launched instance, in Home. Without any arguments, commands for managing instances will apply to the primary instance.
  • Install a desktop environment and a Remote Desktop server.

Launch the instance

You can do this with cloud-init or without it (manual configuration).

With cloud-init

Create a configuration file. It will update/upgrade the system, install the packages we need, and create a new user (cloudy) with a password for us to log in with Remote Desktop. This example uses a plain text password for simplicity but adjust it to your environment's security needs.

cat << EOF > cloud-config.yaml
package_upgrade: true
  - ubuntu-desktop
  - xrdp
  - xsel
  - default
  - name: cloudy
    shell: /bin/bash
    lock_passwd: false
    plain_text_passwd: 'supersecretpwd'
Enter fullscreen mode Exit fullscreen mode

Launch the instance using the configuration file we created:

multipass launch jammy --cloud-init cloud-config.yaml --name primary --cpus 4 --disk 15G --memory 8G
Enter fullscreen mode Exit fullscreen mode

Without cloud-init

You could also configure the instance manually instead. In this case we don't need to create a new user, we'll just manually set a password for the default user and use that one.

multipass launch jammy --name primary --cpus 4 --disk 15G --memory 8G
Enter fullscreen mode Exit fullscreen mode

Connect to the instance to install a desktop environment and a Remote Desktop server.

multipass shell
Enter fullscreen mode Exit fullscreen mode
sudo apt update && sudo apt upgrade -y
sudo apt install ubuntu-desktop xrdp -y
Enter fullscreen mode Exit fullscreen mode

Set a password for the default ubuntu OS user.

sudo passwd ubuntu
Enter fullscreen mode Exit fullscreen mode

Access the instance's desktop

To access the newly-installed desktop we need the IP address of the instance. Find it either by running the ip addr command within the Ubuntu shell or by running multipass list on your Mac host.

Then use that IP address to connect with an RDP client like Microsoft Remote Desktop (available on the App Store). You can use the default user ubuntu if you manually set its password or the user cloud-init created with the password you specified.

Top comments (4)

tsolan profile image
Eugene • Edited

Only question “why?”
I’d understand the reason to install, for instance, Windows, but Linux… beside unix system…

santisbon profile image
Armando C. Santisbon

Here's another example: You can launch a number of Ubuntu VMs as a cloud native Kubernetes cluster, having all of them automatically configured by cloud-init as a MicroK8s node with c-groups enabled, extra kernel modules for NVMeoF, replicated container-attached storage based on OpenEBS, and object storage with MinIO.
Then when you're done with development, deploying to production is very easy whether it's a public cloud, an isolated location at the edge, or a bunch of Raspberry Pis in your homelab because you've already tested everything on a very similar environment.

santisbon profile image
Armando C. Santisbon • Edited

There are many reasons. You could use an Ubuntu environment to test something on your Mac like a snap package or a cloud-init file. This also applies to any machine with an ARM architecture like a homelab where you want to set up machines as your personal "cloud" and launch instances pre-configured with cloud-init.

seenukarthi profile image
Karthikeyan Vaithilingam

I use Linux vm/container in macOS so I can have MSSqlServer for one of my project.