How to Install VirtualBox on Ubuntu [Beginner's Tutorial]

This beginner’s tutorial explains various ways to install VirtualBox on Ubuntu and other Debian-based Linux distributions.
Warp Terminal

Oracle’s free and open-source offering VirtualBox is an excellent virtualization tool, especially for desktop operating systems. I prefer using it over VMWare Workstation on Linux, another virtualization tool.

You can use virtualization software like VirtualBox for installing and using another operating system within a virtual machine.

For example, you can install Linux on VirtualBox inside Windows. Similarly, you can also install Windows inside Linux.

You can also use VirtualBox for installing another Linux distribution within your current Linux system. Actually, this is what I use it for. And, one of the reasons to run Linux in virtual machines is to test it out conveniently.

virtualbox on ubuntu

In this beginner’s tutorial, I’ll show you various ways of installing Oracle VirtualBox on Ubuntu and other Debian-based distributions.

Installing VirtualBox on Ubuntu and Debian-based Linux distributions

The installation methods mentioned here should also work for other Debian and Ubuntu-based Linux distributions such as Linux Mint, elementary OS, etc.

Method 1: Install VirtualBox from the Ubuntu Repository

The easiest way to install VirtualBox on Ubuntu is to search for it in the Software Center and install it from there.

VirtualBox in Ubuntu Software Center
VirtualBox is available in the Ubuntu Software Center

You can also install it from the command line using this command:

sudo apt install virtualbox

However, if you check the package version before installing it, you’ll see that the VirtualBox provided by Ubuntu’s repository may be a bit older.

📋
Pros: Easy installation | Cons: Installs older version

For example, the current VirtualBox version at the time of writing is 7.0.10, the repository includes 7.0.6. This means you may miss out on some newer features introduced in the latest version.

Method 2: Install VirtualBox using a deb file from Oracle’s website

If you want to use the latest version of VirtualBox on Ubuntu, the easiest way would be to use the deb file.

Oracle provides ready-to-use binary files for VirtualBox releases. If you look at its download page, you’ll see the option to download the deb installer files for Ubuntu and other distributions.

📋
Pros: Easily install the latest version | Cons: Can’t upgrade to a newer version without reinstalling
virtualbox downloads available

You just have to download the deb or rpm file as per the distro (here, it is Ubuntu 22.04) and double-click on it to install it. It is as simple as that.

However, the problem with this method is that you won’t get automatically updated to newer VirtualBox releases. The only way is to remove the existing version, download the newer version and install it again. That’s not very convenient, is it?

Method 3: Install VirtualBox using Oracle’s repository

This is the command line method, and it may seem complicated to you, but it offers advantages over the previous two methods. You will get the latest version of VirtualBox, which will be automatically updated with future releases. If that’s what you’re looking for.

📋
Pros: Automatically updates with system updates | Cons: Slightly complicated installation

To install VirtualBox using the command line, you need to add Oracle VirtualBox’s repository to your list of repositories. You then add its GPG key so that your system trusts this repository. Now, when you install VirtualBox, it will be installed from Oracle’s repository instead of Ubuntu’s repository.

If a new version is released, the VirtualBox install will be updated along with the system updates. Let’s see how to do that.

First, add the key for the repository. You can download and add the key using this single command.

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -

Now add the Oracle VirtualBox repository to the list of repositories using this command:

sudo add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"
📋
If you’re using Linux Mint or some other distribution based on Ubuntu, replace $(lsb_release -cs) in the command with the Ubuntu version your current version is based on. For example, Linux Mint 21 series uses Ubuntu 22.04. So, you can replace it with jammy.

Something like this:

sudo add-apt-repository “deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian jammy contrib“

If you’ve read my article on checking your Ubuntu version, you probably know that ‘lsb_release -cs’ will print the code name of your Ubuntu system.

🚧
If you notice "keyring is stored in legacy trusted.gpg", you should not have any issues, but you can choose to fix the keyring legacy error.

In either case, you may also see an add-apt-repository command not found error, you’ll have to install the software-properties-common package in such a case.

Now that you have the correct repository added, refresh the list of packages available through these repositories and install VirtualBox.

sudo apt update && sudo apt install virtualbox-7.0
💡
A good idea would be to type sudo apt install virtualbox– and hit tab to see the various VirtualBox versions available for installation – then select one of them by typing it completely.
virtualbox packages available

How to remove VirtualBox from Ubuntu

Now that you’ve learned to install VirtualBox, I should also mention the steps for removing it.

If you installed it from the Software Center, the easiest way to remove the application is from the Software Center itself. You just have to find it in the list of installed applications and click the Remove button.

Another way is to use the command line:

sudo apt remove virtualbox virtualbox-*
📋
This will not remove the virtual machines and the files associated with the operating systems you installed using VirtualBox. That’s not an entirely bad thing, because you may want to keep them safe and use them later or in some other system. You can manually delete those if not needed.

Finally …

I hope you were able to use one of these methods to install VirtualBox. I’d also advise installing VirtualBox Guest Additions on Ubuntu or whatever guest system you’re using in your VM to get a better and smoother experience.

If you have any tips, suggestions or questions, feel free to leave a comment below.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.