How to install VirtualBox on Ubuntu
This tutorial explains how to install VirtualBox on Ubuntu step by step with practical example. Learn how to add the repository and public keys to download and install the latest version of VirtualBox on the current version of Ubuntu.
Installing VirtualBox in Ubuntu
There are several ways to install software in Ubuntu. Installing it from repository is the safest and the easiest way.
A repository is the collection of installable software. Broadly, Ubuntu divides repositories in two types; default repositories and third party repositories.
Repositories those are owned by it or its partners are referred as the default repositories. Rests are known as the third party repositories.
To download software from the default repositories, no additional configuration is required. Ubuntu automatically adds necessary settings for the default repositories. Due to legal issues, it does not add any settings for the third party repositories. To download software from a third party repository, we must have to add the necessary settings for that repository manually.
Since the repository that contains VirtualBox is a third party repository, we must have to add the necessary settings manually before we can download the VirtualBox from this repository.
To add necessary setting, access shell prompt and run following command.
$sudo add-apt-repository \"deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian bionic contrib\"
In this command,
The command sudo instructs shell to run the command add-apt-repository with super user privilege.
The command add-apt-repository adds the supplied repository settings in the repository source file /etc/apt/sources.list.
Supplied repository settings contain following four pieces of information.
This is the type of software that this repository contains. The keyword deb indicates that
this repository contains the pre-compiled binary packages. The next keyword [arch=amd64] indicates the
hardware architecture for that these packages are compiled. Hardware architecture [arch=amd64] is optional. You may use it or skip it.
This is the location of the repository.
This is the code name of Ubuntu for that this repository provides software.
The bionic is the code name of Ubuntu 18.04. We can type this name statically or can use the command that prints
the code name of Ubuntu. For example, to add this information, we can also use the following command.
$sudo add-apt-repository \"deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib\"
Since each version of Ubuntu uses a unique code name, you should always use the command $(lsb_release -cs) to add the correct code name dynamically.
This keyword indicates that software of this repository uses dependencies.
Software management (adding / deleting repositories, installing / deleting software, etc.)
requires root privileges. The user account you created during installation has the necessary privileges. Type the password for that account when it asks for authentication.
Adding keys to download the VirtualBox
Ubuntu uses keys based authentication to download the software from repositories.
In key based authentication, two keys are used; private key and public key.
Private Key is stored in repository. Repository uses this key to authenticate the client program that downloads software from it. Public Key is stored in Ubuntu. Ubuntu uses this key to download software from the repository.
Oracle provides two public keys for its repository; oracle_vbox_2016.asc and oracle_vbox.asc.
First key is used for Ubuntu 16.04 or higher versions while second key is used for older versions.
To download and install the public key in Ubuntu 16.04 or in newer version, use the following command.
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
To download and install it in older version, use the following command
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
Although it\’s not recommended, yet you can install both keys. If both keys are installed, Ubuntu automatically selects the right key to download the software.
Updating repository database
Any newly added repository does not work until the repository database is refreshed. To refresh the repository database, use the following command.
$sudo apt-get update
Once database is refreshed, VirtualBox can be downloaded from the repository added above.
Ubuntu provides both command line utility and graphic tool to download and install the software.
Installing VirtualBox from CLI
To install it from command prompt, use the following command.
$sudo apt-get install virtualbox-6.0
When it asks to confirm the installation, type y and press the enter key.
Installing VirtualBox from GUI
Click Application launcher icon from right side menu bar and search Ubuntu software or software. From results, click Ubuntu Software.
It opens the Ubuntu Software utility. In Ubuntu Software utility, search the keyword VirtualBox. From the results, select the listing
that contains the Oracle VirtualBox and click the Install button.
Once VirtualBox is installed, it can be accessed from the Application launcher. To access it, click the Application launcher icon and search VirtualBox.
Removing old VirtualBox repository
Oracle recently switched its repository on more secure protocol HTTPS from HTTP.
If you get errors while installing the VirtualBox or unable to install it, make sure you added the updated URL of the repository. Earlier, URL was the following.
This URL no longer works. Correct URL is the following.
If we add new repository URL without removing old repository URL, we get following warning message when installing the VirtualBox.
w: Target CNF (contrib/cnf/commands-all) is configured multiple times in /etc/apt/sources.list:xx and /etc/apt/sources.list:xx
In this message, xx is the line numbers of old and new entries.
To remove this warning message or to remove the old repository, follow these steps.
- Click Application launcher and search \”Software & updates\”.
- Click Software & updates tool. This brings the main screen of the tool.
- Switch to Other Software tab and select the older/duplicates entries and uncheck the box.
- Authenticate the action and click the button reload to refresh the repository database.
That\’s all for this tutorial. If you like this tutorial, please don\’t forget to share it with friends through your favorite social site.