In order to install libvirt, it will first be necessary to install and setup the ports tree.
The basic libvirt utilities and libraries are provided by the libvirt package. To install it along with its dependencies, run sudo portmake install libvirt
.
Once it has finished installing, start the libvirt daemon by running sudo /etc/init.d/libvirt start
. It may be desirable to set this service to start when the system boots.
Libvirt does not provide a hypervisor; rather, it provides an interface for managing a hypervisor. In order to actually run Virtual Machines, it will be necessary to install a hypervisor after installing libvirt. Libvirt supports several different hypervisors. A full list can be found at https://libvirt.org/drivers.html. Instructions for installing a subset of these hypervisors can be found below.
If you are new to libvirt and unsure of which hypervisor to use, Qemu KVM is probably a good choice.
The Qemu KVM hypervisor is provided by the qemu package. This package also provides software virtualization support for the i386, x86_64 and arm architectures. To install Qemu and all of its dependencies, run sudo portmake install qemu
.
Once it has finished, run the command sudo virt-host-validate qemu
. It should not produce any failures. If it produces no failures, then Qemu KVM is ready for use with libvirt.
Full documentation on how to use libvirt can be found at https://libvirt.org/docs.html.