How to Set Up Multipass with VS Code on Mac: A Step-by-Step Guide

Motivation
Recently, I tried to learn some low-level system programming stuff. I am a Mac user, and I thought that everything that works on Linux should also work on Mac. After all, Mac is a Unix-based system 😊. I guess we all heard this. Oh boy! I was mistaken. After attempting to run a few programs, I realized I was wrong.
Below are a few points that restrict you from implementing system programming stuff on Mac.
Kernel Mismatch: macOS ≠ Linux
macOS doesn't have the procfs or sysfs filesystems used heavily for interacting with kernel objects.
System programming, it requires a GCC toolchain, which you’d need to install using cross-compilation tools, and it comes at a price.
These points suggest that doing system programming on macOS is not easy. Most of the necessary tools are not available on the system. You can either use virtual machines or Docker, but these options come with some performance costs. After some research, I found a tool called Multipass.
What is Multipass?
Multipass is a super simple way to run an actual Ubuntu Linux VM on your Mac, without the usual “VM setup headache”. You install Multipass, run one command, and you get a clean Ubuntu machine in seconds. It’s made by Canonical (the Ubuntu guys), so the experience feels very “Ubuntu native” instead of a random virtual machine tool.
Using Multipass, you keep your Mac as your main workstation (terminal, editor, browser, notes, etc.), but all the “Linux-only” work happens inside the Ubuntu VM. So you can install gcc, make, gdb/lldb, kernel headers, compile C programs, and build/load kernel modules (inside the VM). For learning system programming, this is almost the best of both worlds, i.e., Mac + Linux.
How to Install multipass?
Open a search engine of your choice and run a search for “multipass”. Open the first result and search that will open Ubuntu documentation in that page, search (using cmd + f) for
Install MultipassOr go to this url.Either you can download the installer or you can install using
brew.Installing through the installer is very straightforward, and to install using
brew, you need to runbrew install multipass. It will take a couple of minutes to install.Now, to confirm if it’s been install you need to run
multipassIn the terminal, you will see a bunch of helper commands, something like below
Now, we know that it is a lightweight virtual manager, which is currently empty, and we need to install an instance.
To do so, we need to run the command in the terminal
multipass shell. It will take some time to create an instance namedprimary. It will install a Ubuntu virtual machine.After some time, when it is done, the prompt will end, and then we need to enter the shell by running
multipass shell primary. We will then be inside the Ubuntu virtual machine, and we will be able to see the screen like below
How to connect Multipass with Visual Studio Code?
Now that our multishell is ready, you can see it is just an terminal based ubuntu system, and we don’t have gui to interact with. We can’t install VS Code inside it to access the environment. So, to harness the power of the Ubuntu environment, we need to connect VS Code on our Mac system to the Ubuntu system. We need to follow the steps below.
Inside the Ubuntu terminal, run the following command:
sudo vim /etc/ssh/sshd_configAnd we will make some changes in the config file to make password-based login into the system.Inside the file, find “KbdInteractiveAuthentication no” and change it to
yessomething like thisKbdInteractiveAuthentication yes.Now, since we made the changes in the system, we will reload the daemon to see the effect of the changes made. To do so, run the command
sudo systemctl daemon-reload.Next, we will run
sudo service ssh restartso that a remote ssh connection can be made.Now, we will reset the password of the instance i.e
ubuntu.(Note:ubuntu@primaryWhat we can see in the prompt hereubuntuis the system name andprimarythe user name). Also, remember this password as it will be used to connect our VS Code with this Ubuntu instance.We will run the command
sudo passwd ubuntu. It will ask to enter and re-enter the password.Now, open the Vs code and move to the Extensions tab and search for “remote development” and install the first result.

After installing this extension, you’ll be able to see a computer-like icon below the
Extensionbutton in VS Code. It is nothing but the “Remote Development” extension. Click on that, and it will open a panel with a list ofSSHBut it will be empty since we have just installed the extension.
Click on the “+” button in the SSH section, and it will open an input box where we will enter
ubuntu@192.168.2.2(192.168.2.2 is the ip address of our Ubuntu instance, which we can get by running the commandhostname -Iin theubuntu@primaryterminal).
Press Enter twice, and now you will be able to see an entry under
SSHsection with the name of ip address, i.e., 192.168.2.2.Now, click on the entry inside the SSH list, and you’ll see a prompt to enter the password. Enter the same password you added for the Ubuntu system.

Now, this will connect our VS Code with the Ubuntu instance. To confirm this, create a directory inside the Ubuntu machine, say
test, and inside the vscode click the “Open Folder” button, and you will see thetestdirectory listed in the folders list. This confirms that our VS Code and Ubuntu instance are connected.
Next, we will run some sample C code.
Writing and running a sample C program in a multipass environment?
Now we know how to connect our VS Code with the Multipass environment. We will now run a sample C program to complete the motive of this blog. For this, we need to install gcc to run C/C++ programs. We can install gcc by running sudo apt install build-essential in ubuntu shell. This will install the gcc program. We can confirm if its install by running gcc —version.
Finally, we can create a sample hello_world.c C file in the test folder we created earlier in the Ubuntu instance by running touch hello_world.c or simply in the VS Code. You can see the file in the SSH section of VS Code, something like this.

Add the following small code snippet to it
#include <stdio.h>
int main() {
printf("Hello, World\n");
return 0;
}
And finally, we can compile the program through the Ubuntu terminal by running gcc hello_world.c and then by running ./a.outIt will print the result in the terminal.

Conclusion
Multipass is the easiest way to get a clean Ubuntu Linux environment on macOS without changing your main setup. It keeps your Mac workflow intact while giving you real Linux tools and behavior, which is perfect for system programming.
I hope you like this blog on installing and setting up Multipass. If you have any questions, please comment below. Thanks for reading 😊.
NOTE: If you wish to learn C/C++ and System Programming in great detail. You can connect and take training from Bhavith Achar, who is the founder and creator of e-grasp.com. He is an excellent C/C++ Engineer and a teacher, and I have taken System Programming training from him.



