### Micro.Blog (Patrick H. Mullins)
[Back] - Date: 2020-10-14 @ 08:54 PM EDT by PHM / Developing with Multipass

In recent years testing cross-platform code (Linux, UNIX, Windows) and/or web applications has gotten a good bit easier. There was once a time when the only option we had was to write our code locally and then upload it to a test server. These days we have a choice between testing our code online in a virtual private server (VPS) or locally on our own development machines. Many developers pick the VPS route because they feel that testing locally is often more trouble than it's worth. That might have been true a few years ago. However, these days we have applications like Vagrant and Multipass to help us spin up and maintain local testing environments.

Multipass, available for macOS, Linux, and Windows, is an application from Canonical that interfaces with the local operating system's native hypervisor (Hyper-V, HyperKit, and KVM) and provides a command-line interface for launching, managing, and working with custom-tuned Ubuntu virtual machines. With Multipass we can quickly launch instances of Ubuntu and initialize them with cloud-init metadata just like the cloud providers, automatically download the most recent Ubuntu images from Canonical, and share files and/or folders between our local home directory and our instances. Combine all of the above and we have a tool that can easily provide a stable, easy-to-use development environment.

Installing Multipass

Mutipass is available for macOS, Linux, and Windows. Standalone installers can be downloaded from the homepage or we can install the app via our operating system's package manger.

macOS users can use Home Brew:

$ brew install multipass

Linux users can use the published snap package:

$ snap install multipass

Windows users need to install Multipass via the standalone executable.

Using Multipass

Now that we have Multipass installed lets take a look at some basic commands that will allow us to start or stop an instance, list all available instances, check what images are available to create and instance from, open a shell to a running instance, and share files with a running instance.

Let's get things going by covering how to create, start, and stop an instance. To create and start an instance we should use the following command:

$ multipass launch -n <instance_name>

Note: <instance_name> is whatever we want to call the instance. If we don't provide a name Multipass will create a random one for us. Also, by default, it will use the latest Ubuntu image to create our new instance. Let's go ahead and make sure our new instance was created. The multipass list command lists all created instances and provides the name, state, IP address, and image type for each.

$ multipass list

Name                    State             IPv4             Image
devbox                  Running           192.168.64.4     Ubuntu 20.04 LTS

We can also use the launch parameter to define basic options like disk and memory size and how many cpus the instance will use. We might want an instance running 18.04 LTS with 512MB of RAM, 1 CPU, and 5GB of space. We can create our custom instance like this:

$ multipass launch 18.04 -c 1 -d 5G -m 512M -n <name>

Not sure what Ubuntu images are available? We can display all available images using the multipass find command:

$ multipass find

Image                       Aliases           Version          Description
16.04                       xenial            20200922         Ubuntu 16.04 LTS
18.04                       bionic            20200922         Ubuntu 18.04 LTS
20.04                       focal,lts         20200921.1       Ubuntu 20.04 LTS

This command lists the image name, alias, version, and a description for each image that's available for use. Now let's start, restart, and stop an instance. We can do that with the following commands:

$ multipass start <instance_name>
$ multipass stop <instance_name>
$ multipass restart <instance_name>

Instance Info

We can list get basic information about our instances like IP, mount points, system load, and disk usage by using the multipass info command.

$ multipass info <instance_name>

Name:           devbox
State:          Running
IPv4:           192.168.64.2
Release:        Ubuntu 20.04.1 LTS
Image hash:     d18a9d2b890d (Ubuntu 20.04 LTS)
Load:           0.84 0.31 0.11
Disk usage:     1.4G out of 4.7G
Memory usage:   128.8M out of 981.4M
Mounts:         /Users/pmullins/Multipass/devbox => /var/www/html
                    UID map: 501:default
                    GID map: 20:default

Shelling into an Instance

Now that we have an instance running we can open a shell directly to that instance and do whatever we'd like. Use the following to open a shell on a running instance:

$ multipass shell <instance_name>

Note: The shell command will launch our default terminal app and connect to the running instance.

Creating Mount Points

Finally, let's create a mount point between the local filesystem and a running instance. This is what I like to do when I'm working on a web app and need to test it locally on a Multipass instance.

The command to create a mount point between systems is:

$ multipass mount ~/some/local/path instance_name:/some/path

In my case I created a mount point from my ~/home/devbox directory to the /var/www/html directory inside the devbox instance:

$ multipass mount ~/Multipass/devbox devbox:/var/www/html

And just like that I can now create and edit the files that comprise my web application and those changes are instantly mirrored in the devbox instance. Pretty neat, right? These more where that came from too. I suggest you spend some time checking out the rest of the documentation. There's plenty in there that I wasn't able to cover in this article.

Conclusion

Canonical's Multipass application is one of those apps that you never knew you needed until you tried it. At least that's how it worked out for me. Is it for everyone? No, it only supports Ubuntu images for the time being and it's not quite as flexible as HasiCorp's Vagrant. However, that being said, if you're a developer who wants to write and test code locally with a minimum of muss and fuss, then Multipass really is the way to go.