Take Control of VMs and Install VirtualBox on Ubuntu 20.04

Published:12 August 2022 - 9 min. read

Nicholas Xuan Nguyen Image

Nicholas Xuan Nguyen

Read more tutorials by Nicholas Xuan Nguyen!

A wise man once said, “With great power comes great responsibility.” The same can be said about virtual machines (VMs). VMs are gaining popularity because they offer a lot of power and flexibility. But all this power can be confusing for newcomers. Well, unless you have VirtualBox on Ubuntu 20.04 machine.

In this tutorial, you’ll learn how to install VirtualBox and how you can take control of your VMs without losing yourself in the process.

Ready? Start managing your VMs like a pro with VirtualBox!

Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

  • An Ubuntu 20.04 system.
  • A user account with sudo privileges – This tutorial uses a root account, but you can also use a regular account with sudo privileges.

If you use a non-root user, prepend sudo on each command in this tutorial.

  • An SSH client of your choice – This tutorial assumes that you’ve logged/SSH’d into your Ubuntu 20.04 system.
  • A minimum of 4GB of RAM – VirtualBox recommends at least 16GB for optimal performance.
  • A minimum of 20GB of free storage space – Each VM you create needs its own storage.

In real-world usage, the amount of memory and storage you need will depend on how many VMs you create and what you plan to do with them.

  • An OS image file (ISO) – This tutorial uses an ISO image of Windows 10 (32-bit).

Installing VirtualBox on Ubuntu 20.04 via APT

The base repositories for Ubuntu 20.04 include VirtualBox, but it doesn’t come installed by default. The easiest way to install VirtualBox on Ubuntu is to use the APT package manager. This method works whether you’re using Ubuntu Desktop or Server.

Note that the version of VirtualBox in the repositories may not be the latest and greatest. But no worries. You can install the latest version using Oracle’s official repository, which you will learn about in the following section.

To install VirtualBox from the Ubuntu repositories using APT:

1. Run the apt update command below to update the list of available packages.

apt update -y
Updating the list of available packages
Updating the list of available packages

2. Next, run the below apt install command to install VirtualBox and the extended pack.

The extended pack is a set of additional features for VirtualBox that lets you use certain features, such as USB 2.0 and 3.0 support, Remote Desktop Protocol (RDP), etc.

apt install virtualbox virtualbox-ext-pack -y
Installing VirtualBox and the extended pack
Installing VirtualBox and the extended pack

3. Select OK, and press Enter after reading the VirtualBox Extension Pack Personal Use and Evaluation License (PUEL) terms.

Reading the VirtualBox Extension Pack Personal Use and Evaluation License (PUEL)
Reading the VirtualBox Extension Pack Personal Use and Evaluation License (PUEL)

4. Now, select Yes, and press Enter to accept the Oracle Binary Code License Agreement for the VirtualBox Extension Pack.

Accepting the Oracle Binary Code License Agreement
Accepting the Oracle Binary Code License Agreement

The installer will download and install all the necessary files, as shown below. Wait for the process to complete. That’s it! You’ve successfully installed VirtualBox on your machine using APT.

Unpacking the VirtualBox extension pack
Unpacking the VirtualBox extension pack

5. Finally, run the following command to start using VirtualBox or open it from the Applications menu.

This step applies when opening VirtualBox regardless of which method you used to install the application in this tutorial.

virtualbox

The main VirtualBox Manager window appears, as shown below, where you can manage your VMs.

Opening the VirtualBox
Opening the VirtualBox

Installing VirtualBox from Oracle’s Official Repository

You’ve learned to install VirtualBox using the APT package manager, a quick method. But that method has one major downside; you will not get the latest version of VirtualBox.

If you prefer to get the latest version of VirtualBox, you need to install it from Oracle’s official repository. Oracle releases new versions of VirtualBox frequently. Note that this method is a bit more complex than the previous one.

To install VirtualBox from Oracle’s official repository, you first need to add the Oracle repository key to your system:

1. Run the wget command below to download and add the Oracle repository key to your keyring. This key ensures that the packages you install using this repository are valid and come from a trusted source.

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
Adding the Oracle repository key to the keyring
Adding the Oracle repository key to the keyring

2. Next, run the following add-apt-repository command to add the Oracle repository to your system. This repository contains the latest versions of VirtualBox for Ubuntu.

add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"
Adding the Oracle repository to the system
Adding the Oracle repository to the system

3. After adding the repository, run the below apt update command to update the APT cache and apply the new changes.

apt update -y
Updating APT cache to apply changes
Updating APT cache to apply changes

4. Run the apt cache command to check which version of VirtualBox is available in the official repositories.

apt-cache policy virtualbox

Pick the latest version of VirtualBox from the list to install.

Checking available VirtualBox versions from the repositories
Checking available VirtualBox versions from the repositories

5. Now, run the apt install command to install the latest VirtualBox version you picked from step four.

apt install virtualbox-6.1 -y
Installing VirtualBox from Oracle’s official repository
Installing VirtualBox from Oracle’s official repository

Alternatively, you can copy and paste the apt install virtualbox- command to your terminal and press Tab to autocomplete the version number.

All the versions currently available will be displayed, as shown below. Choose the newest one to install. This behavior works for any supported Ubuntu release and VirtualBox version combination.

Auto-completing VirtualBox versions
Auto-completing VirtualBox versions

6. Next, run the following command to download the VirtualBox Extension Pack. Ensure the version number of the extension pack matches the version of VirtualBox you just installed (6.1).

You can find the download link for the extension pack on the same page where you found the download link for VirtualBox.

wget https://download.virtualbox.org/virtualbox/6.1.26/Oracle_VM_VirtualBox_Extension_Pack-6.1.26.vbox-extpack
Downloading the VirtualBox Extension Pack
Downloading the VirtualBox Extension Pack

7. Lastly, run the VBoxManage command below to install the VirtualBox Extension Pack.

VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-6.1.26.vbox-extpack

Type y and press Enter when prompted to agree to the terms, as shown below.

Installing the VirtualBox Extension Pack
Installing the VirtualBox Extension Pack

Install VirtualBox using a Deb Package

If you’re not a fan of adding third-party repositories to your system, you can install VirtualBox using a deb package. You can download the deb package from Oracle and install it manually on your system.

To install VirtualBox from a .deb package:

1. Open your favorite web browser, head to the VirtualBox Linux downloads page, and look for your Linux distribution. This tutorial goes for the VirtualBox 6.1.34 for Ubuntu 20.04.

Right click on the hyperlink, as shown below, and choose Copy link address to copy the download link.

Copying the download link for the VirtualBox deb package
Copying the download link for the VirtualBox deb package

2. Now run the wget command to download the .deb package. Replace the link below with the download link you copied in step one.

The -P option is used to specify the destination directory, which in this case is the Downloads folder.

wget https://download.virtualbox.org/virtualbox/6.1.34/virtualbox-6.1_6.1.34-150636.1~Ubuntu~eoan_amd64.deb -P Downloads
Downloading the VirtualBox deb package
Downloading the VirtualBox deb package

3. Now, run the following commands to switch to the Downloads directory and install VirtualBox.

cd Downloads
dpkg -i Downloads/virtualbox-6.1_6.1.34-150636.1~Ubuntu~eoan_amd64.deb
Installing VirtualBox using the deb package
Installing VirtualBox using the deb package

If you get an error saying that some dependencies are not satisfied, run the following command to fix them.

apt-get install -f

Creating Your First VM

You’ve successfully installed VirtualBox on your machine and are ready to create your first VM. This tutorial uses a Windows 10 image to create a VM, but you can choose any you prefer.

To create your first VM:

1. Launch VirtualBox if it’s not already open.

2. Click the New button on the toolbar to create a new VM.

Initiating creating a new VM
Initiating creating a new VM

3. Configure the name and operating system (OS) for your VM with the following:

  • Name – Provide a name for your VM. This tutorial’s choice is W10.
  • Machine Folder – Choose the folder where you want your VM to reside.

By default, your VM files are stored in the home directory under the VirtualBox directory.

  • Type – Select the type of OS for your VM. This tutorial’s choice is Windows 10 (32-bit).
  • Click Next to continue.
Creating Your First VM
Creating Your First VM

4. Now, specify how much memory (RAM in MB) you want to allocate for your VM, and click Next.

Allocating the VM’s memory
Allocating the VM’s memory

5. Select the Create a virtual hard disk now option on the next screen, and click Create.

This option lets you create a virtual hard disk (a file) that stores all the data for your VM, including the operating system, applications, and files.

Creating a virtual hard disk
Creating a virtual hard disk

6. Next, choose the VDI (VirtualBox Disk Image) option, which is a good choice for most users, and click Next.

But if you’re running VirtualBox on an enterprise environment, choose one of the other two options instead.

Selecting a hard disk file type
Selecting a hard disk file type

7. On the next screen, choose the storage type for your virtual hard disk. But for this tutorial, select the default option (Dynamically allocated) and click Next.

Why use dynamic allocation? This option is more efficient with storage space because it only allocates the amount of disk space the VM uses.

Selecting the VM’s storage type
Selecting the VM’s storage type

8. Choose a name for the virtual hard disk, allocate the storage space for your VM, and click Create. You can choose the storage size you prefer, but this tutorial’s choice is 20 GB.

Allocating 20 GB of space for the VM
Allocating 20 GB of space for the VM

Once the VM is created, you’ll see the VM listed in the left pane of the VirtualBox window.

Verifying the new VM
Verifying the new VM

Attaching a Bootable Media

You’ve just created your first VM on VirtualBox. But right now, even if you start the VM, it won’t do anything since you haven’t attached any bootable media to the VM.

To attach a bootable media to your VM:

1. Click on your VM in the left pane, and click Settings from the toolbar to access your VM’s settings.

Accessing the VM’s settings
Accessing the VM’s settings

2. On the Settings window, click Storage in the left pane —> Empty drive under Storage Devices —> the disc icon under Attributes.

A context menu opens where you can choose how to attach a bootable media for the VM (step three).

Accessing bootable media options
Accessing bootable media options

3. Select Choose disk file from the dropdown menu to look up your bootable media (ISO).

Choosing a disk file as the bootable media
Choosing a disk file as the bootable media

4. Now, locate and select your ISO image file.

Locating the Windows 10 ISO file
Locating the Windows 10 ISO file

5. Click OK to close the Settings window.

Saving the settings changes
Saving the settings changes

6. Lastly, click Start at the toolbar to start your new VM.

Starting the new VM
Starting the new VM

You’ll see a new window open with your VM booting up. At this point, you can install your OS (Windows 10) as you usually would on a local machine.

After installing the OS, you can boot up your VM and use it just like any other computer.

Starting up the VM to set up its operating system
Starting up the VM to set up its operating system

Increasing VM’s Video Memory (VRAM) to Improve Performance

Did you notice slowness on your VM after setting up its OS? By default, the VRAM allocated to a VM is only 128 MB, which is also the max VRAM you can allocate, as shown below.

Showing max VRAM to allocate
Showing max VRAM to allocate

This amount of VRAM is fine if you have only one or two windows open. But, if you try to do anything graphics-intensive, like testing your video games on different OS, you’ll need more VRAM.

To increase the video memory for your VM:

1. Click on the Machine menu —> ACPI Shutdown, as shown below, or press Host+H keys to shutdown your VM. The Host key is the right Ctrl key on your keyboard.

Shutting down the VM
Shutting down the VM

2. Next, run the below command to increase (modifyvm) your VM’s VRAM to 256. This command doesn’t provide output but sets your VM’s max VRAM to 256. Be sure to replace W10 with your VM’s name.

Note that 256MB is the maximum video memory you can allocate.

VBoxManage modifyvm "W10" --vram 256

3. Start your VM again, and you’ll notice the difference in performance.

4. Finally, open VM’s settings, click on Display in the left pane and see the Video Memory is set to 256 MB, as shown below. This output indicates that your Windows 10 VM’s video adapter now uses 256 MB of video memory.

You can experiment with different amounts of video memory to find the sweet spot for your needs. But remember that you can’t allocate more than 256 MB of video memory to a VM.

Verifying new VRAM allocation
Verifying new VRAM allocation

Conclusion

In this tutorial, you’ve learned how to install VirtualBox on your Ubuntu 20.04 system and create your first VM. You’ve also improved performance by increasing your VM’s VRAM to your liking. With these skills, you can test different OSs and run multiple VMs simultaneously without any slowdown.

VirtualBox, no doubt, is one of the best virtualization software available. This software is free, open-source, and cross-platform.

Many system administrators and developers use VirtualBox with a local Kubernetes cluster for development and testing purposes. Would you do the same?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!