Harish Kumar

Software Engineer | Go | Python | AI/ML

Installing Ubuntu environment on Mac using Multipass

I wanted to setup Ubuntu instance for testing a workload and I was contemplating whether to use a digitalocean droplet and found multipass, and wanted to explore that route.

Installation and Launch the instance

The installation steps are quite straight-forward in Mac environment using homebrew and the resource limits, such as CPU, Memory and Storage limits can be specified on instance launch.

brew install --cask multipass
multipass launch --name dev-vm --cpus 2 --mem 2G --disk 10G

We can also use cloud-init to configure the startup of the instance.

Mount files if necessary.

multipass transfer file.txt dev-vm:/home/ubuntu/

Configure and setup SSH

Multipass also provides a very minimalistic and clean UI application installed to view the instances.

Diagram

The instance will be launched and it runs on the private subnet mask on the router and so the instance IP will be 192.168.x.x.

Next, I tried to SSH shell via ssh and also multipass exec but ran into issues.

ssh ubuntu@192.168.x.x
multipass exec dev-vm -- ls /

ssh connection failed: ‘Failed to connect: No route to host

Troubleshooting, I found that I need to setup local passphrase in Mac and finally, login worked. Refer to related Github issues section at the end of this post.

multipass set local.passphrase
sudo multipass authenticate
sudo multipass shell dev-vm

Remote SSH through VSCode

Next, I wanted to explore the Remote SSH to this instance with VSCode but encountered few issues.

Troubleshooting, I had to tweak few configs in users profile settings.json

  • settings.json config:
 "github.copilot.advanced": {
        "debug.useElectronFetcher": true
    },

  • Toggle the settings in System Settings -> Local Network so VSCode can remote SSH to containers on the host network.

    Diagram

  • Can also update the entryies in config /.ssh/config for VSCode.

Host 192.168.x.x
HostName 192.168.x.x
User ubuntu
Port 22
IdentityFile ~/.ssh/id_rsa

The BEST thing is that VSCode with Github Copilot works flawlessly while on remote containers. Hurray!

Diagram

Useful Commands

  • list all instances: multipass list
  • stop instance : multipass stop <instance_name>
  • delete instance : multipass delete <instance_name>
  • purge instance:multipass purge

Related Github issues:


I felt this approach is very convenient easy to launch a Linux based environment in Mac machine and do my work. A caveat is that the instance can be relaunched on a different IP address on system restart and need to tweak the config accordingly.