In this page, you will learn how to configure your local machine to run virtual machine that is provisioned with Vagrant. The provisioned guest machine is running on Debian 12 (Bookworm) with all the tools to run any of the code sections without configuring your own machine to do any of these. Also, the author would make sure that all the code that is shared will work no matter what.
To start with, we need a hypervisor, and we plan to use VirtualBox just because it’s simplicity. Both Vagrant and VirtualBox are free to download from their websites.
If both Vagrant and VirtualBox are ready to be used in your terminal of
your choice, you can run the first Vagrant command to initialize a file
named Vagrantfile
in your current directory. If you want to store this
file in a dedicated directory, for now, we can call it dev-machine
.
vagrant init debian/testing64
This will create the Vagrantfile
that we will change with the
following.
Vagrant.configure("2") do |config|
config.vm.define "earth", primary: true do |server|
server.vm.box = "debian/bookworm64"
server.vm.provider :libvirt do |guest|
guest.cpus = 2
guest.memory = 2048
end
server.vm.network :private_network, ip: "192.168.33.10"
#
# build-essential: compilers and other tools to create packages on Debian
# cmake: cross-platform build system to build
# libopenmpi-dev: includes both MPI development headers and binaries
#
server.vm.provision :shell, inline: <<-SHELL
apt-get update
apt-get install -y build-essential cmake libopenmpi-dev
SHELL
end
end
Now, we can run following command to start the virtual machine.
vagrant up
Vagrant will download the virtual machine image, and then run the provision script. Whenever it is done, we can run following command to get into the SSH session
vagrant ssh