Setting up a virtual machine can be a great way to test software or alternative operating systems on your computer without altering or putting your current system at risk.

Follow along to install VirtualBox on Linux and create your very first virtual machine.

What Is a Virtual Machine?

A virtual machine is a virtualized or emulated substitute for a real computer that provides the functionality necessary to run an entire operating system. In other words, a virtual machine allows you to run a second computer (commonly referred to as a guest system) within your existing computer environment (commonly referred to as the host system).

In most cases, the guest system is completely isolated from the host and runs independently. This creates a perfect platform for testing new operating systems or experimenting with unknown or untrusted software without putting the host system at risk.

There are various ways to go about setting up a virtual machine on your Linux system but one of the easiest is to use VirtualBox from Oracle. It is free to use for non-commercial use and will allow you to set up a virtual system in just a few steps using practically any type of operating system installation media.

Downloading and Install VirtualBox on Linux

Before you start, you’ll need to install VirtualBox on your system. You can either download it directly from Oracle or, in some cases, you may be able to install it from your distribution’s package manager.

Installing VirtualBox Through Your System Package Manager

If VirtualBox is available in your distro’s software repositories, installing through your package manager will be the fastest, easiest, and safest way to go. A prepackaged version is likely to integrate better with your specific operating system and deliver better performance.

To see if VirtualBox is available directly through your distro, open a terminal and enter the appropriate command depending on the Linux distro you're currently using.

For Debian-based systems such as Ubuntu and Linux Mint:

        sudo apt install virtualbox
    

For RHEL-based systems such as CentOS and Fedora:

        sudo dnf install virtualbox
    

On Arch Linux and its derivatives:

        sudo pacman -S virtualbox
    

If VirtualBox is available, answer yes to any installation prompts and everything should install within a few moments. When the installation completes, you’ll need to reboot your system. You can then skip the next section and jump right to the instructions on how to set up your first virtual machine.

If you get an error saying that VirtualBox is not found, continue below to download and install it from the official website.

Downloading and Installing VirtualBox From Oracle

To download VirtualBox from Oracle and install it, you’ll need to head to the VirtualBox Linux download page. From there, select the installation package that best fits your operating system.

Download: VirtualBox

Once you’ve downloaded the installation package, open a terminal and switch to the directory where you saved the file. Enter the appropriate command below to start the installation process (substituting the file name with the exact name of the file you downloaded).

For Debian-based systems such as Ubuntu and Linux Mint:

        sudo dpkg -i VirtualBox-Version.X.X.deb
    

For RHEL-based systems such as CentOS and Fedora:

        sudo rpm -i VirtualBox-Version.X.X.rpm
    

Your system may download necessary support packages before the installation begins. Once the installation is complete, you will need to reboot your system before launching VirtualBox.

Creating a Virtual Machine With VirtualBox

Once you have VirtualBox installed, setting up your first virtual machine is relatively easy. When you launch VirtualBox for the first time, you'll be presented with a short menu. From there, simply click on the New button.

VirtualBox New Button

VirtualBox will ask you to give your new virtual machine a name. Choose the storage location for the virtual machine files, and select the operating system that you're going to install.

VirtualBox Name and OS Options

VirtualBox has built-in support for nearly all major operating systems, including Windows, Linux, macOS, and even BSD and Solaris.

After you select the operating system, VirtualBox will ask you to select how much RAM to allocate to the virtual machine while it is running. It's generally recommended that you give your guest operating system at least 4GB of RAM.

If you have a large amount of RAM you may get better performance by raising the amount allocated to your guest system. You should not, however, assign more than half of your system's physical RAM to the virtual machine.

Related: Top Linux Operating Systems You Should Try in a Virtual Machine VirtualBox will then ask you if you want to create a virtual hard disk for your new virtual machine. Since this is going to be your first virtual machine, you want to select Create a virtual hard disk now. When asked what type of hard disk you want to create, just leave this setting at the default, VDI or VirtualBox disk image.

Next, VirtualBox will ask you if you would like the hard disk to be dynamically allocated or set at a fixed size.

If you set the hard drive to dynamically allocated, VirtualBox will start the machine with a relatively small virtual hard drive that will grow as more space is needed (up to the maximum that you set). Fixed-size virtual disks generally perform better, but the difference is really only noticeable if you are creating a large drive.

VirtualBox Hard Disk Settings

On the next screen, set the maximum size of the hard drive for your virtual machine. For many systems, VirtualBox will default to 8GB. Although this might work for minimal installs of some operating systems, if you plan to do more than just use your new virtual machine for casual experimentation, you should set the maximum hard drive limit a bit higher to at least 15 or 20GB.

With the configuration set, VirtualBox will drop back to the main menu and you should see an entry for your new virtual machine on the left side of the VirtualBox window. Click on your virtual machine and you will see a button labeled Start on the top right.

VirtualBox Start Button

Click on Start to power up your virtual machine. VirtualBox will open a dialog asking you to select the startup disk. Your startup disk will be the installation disk for whichever operating system you wish to install.

Simply click on the folder icon and select the image you want to use. Click the Add button on the top left and navigate to the directory where you have stored your installation media.

VirtualBox Add Boot Image

Select the disk you'd like to use. Then, click on Choose to continue.

VirtualBox Startup Disk

Back at the select startup disk screen, you should now see the installation image that you've selected. Press Start and your new virtual machine should start up and load the installation media.

From there all you need to do is just follow the on-screen instructions for whichever operating system you're installing. When the installation is complete, restart your virtual machine, and it should load up into the new guest operating system, ready to use.

From this point on, whenever you want to use your new virtual machine, all you’ll need to do is load VirtualBox and click Start.

Working With Virtual Machines on Linux

Congratulations! You just set up your first virtual machine! But why stop here? You can set up as many VMs as you have space for, and there are plenty of interesting and exciting things you can do with them.