A Beginner’s Guide to Multipass: Create and Manage Ubuntu VMs in Minutes
Whether you’re developing, testing or deploying your application or you have to work with different OS or some other reasons, you might have created virtual machines. Like me, you might have explored different virtualization tools such as Oracle VirtualBox or VMware Workstation and downloading the OS image, allocating resources, interacting with the VM can be messy. Last year, I discovered Multipass which provides simpler and cleaner way of creating and maintaining Ubuntu instances with intuitive CLI commands.
Multipass is a tool to generate cloud-style Ubuntu VMs quickly on Linux, macOS, and Windows. It gives you a simple but powerful CLI that allows you to quickly access an Ubuntu command line or create your own local mini-cloud. This blog will show you how easy is to be create and manage Ubuntu VMs (instances) using Multipass.
Multipass is available for Linux, macOs, or Windows. To install it on your OS of choice, please follow the instructions given here. Note: This tutorial demonstrates use on Linux, specifically Ubuntu, but the experience on any OS should be similar.
Install Multipass
To get started with Multipass, you’ll need to install it first. Multipass is available as a snap package in Linux. So, make sure you have snap
installed. Verify if snap is installed or not with following command
snap --version
If snap
is not installed, install it by running following commands
# update and upgrade the packages to latest version
sudo apt update
sudo apt upgrade -y
# install snapd
sudo apt install snapd
Once snap
is installed successfully, install Multipass by simply running
sudo snap install multipass
After Multipass is installed, you can verify and check details about the Multipass with snap info
command:
snap info multipass
If you want to uninstall/remove Multipass from the system, you can simply run
snap remove multipass
Create an Ubuntu Instance
With Multipass, all it takes is a single command multipass launch
to create an instance
multipass launch
This creates a new ubuntu virtual machine with default settings, using the latest Ubuntu LTS (Long Term Support) version as a base image.
You can also create instance with specific OS image as well. To find out what images are available, just run
multipass find
This command will display a list of all currently available images. Depending on the time you’re reading this blog, different images might be available over time.
To launch an instance with a specific image , pass the image name or alias to multipass launch
. If you want to give specific name to the instance, add --name
option to the command line
multipass launch 22.04 --name myUbuntuInstance
Running above command creates an Ubuntu 22.04 instance named myUbuntuInstance. To get more details about the instance, simply run
multipass info myUbuntuInstance
By default, Multipass will assign 1 CPU, 1GB RAM, and 5GB disk space. We can specify resources explicitly as well when creating an instance
multipass launch 22.04 --name myUbuntuInstance2 --disk 10G --memory 2G
Above command will create an Ubuntu 22.04 instance named myUbuntuInstance2 with 2GB RAM and 10GB disk space. You can verify configuration and resources with multipass info
command
With multipass list
command, you can view all the instances
Connect to the Instance
Now, to connect to the Ubuntu instances, simply run multipass shell instance-name
multipass shell myUbuntuInstance
This will start the instance if it is stopped or suspended and open the shell prompt. By default, you will be logged in as ubuntu user.
Now you’re connected to your Ubuntu instance. Just like any other Ubuntu installation, you can run commands and explore it. If you want to exit from the instance, simply run exit
or press Cntrl+D
.
Manage Instances
Now that you’ve created your instance, Multipass offers range commands to start, stop, restart, and even remove your instances with ease:
Start an Instance
To start an instance, simply run
multipass start instance-name
# starting myUbuntuInstance
multipass start myUbuntuInstance
You can start multiple instances or all instances at once with following command
# start multiple instances
multipass start myUbuntuInstance myUbuntuInstance2
# start all instances
multipass start --all
To restart, just run
# restarting myUbuntuInstance
multipass restart myUbuntuInstance
Stop the Instance
To stop the server, simply run
multipass stop instance-name
# stopping myUbuntuInstance
multipass stop myUbuntuInstance
You can stop multiple instances or all instances at once with following command
# stop multiple instances
multipass stop myUbuntuInstance myUbuntuInstance2
# stop all instances
multipass stop --all
Remove an Instance
You can remove an instance, either temporarily or permanently. To remove an instance temporarily i.e. move an instance to the ‘recycle bin’, you can execute below command:
multipass delete myUbuntuInstance
Now, if you list
the instances, you will see that it is actually just marked for deletion (or to put it in other words, moved to the recycle bin):
Since this instance has been marked as deleted and not deleted permanently, it can later be recovered:
If you want to delete an instance permanently, you first have to delete it and then purge:
# mark the instance as deleted
multipass delete myUbuntuInstance
# remove it permantenly
multipass purge
The
multipass purge
command will permanently remove all instances deleted with themultipass delete
. This will destroy all the traces of the instance, and cannot be undone.
The multipass
CLI (command line interface) client is used to communicate with the Multipass service to create, manage, and interact with Multipass instances using various subcommands. You can learn more about various commands available here which allows you to interact with a Multipass instance.
Multipass offers a refreshingly simple and user-friendly approach to creating and managing Ubuntu virtual machines. Dive deeper into the official documentation to unlock the full potential of Multipass and explore advanced VM management features!