Linux

How to Install VirtualBox in Linux?

How to Install VirtualBox in Linux

VirtualBox is one of the most popular and powerful virtualization tools used for running multiple operating systems simultaneously on a single machine. Whether you need to test software, run Windows applications on Linux, or simply use another OS without dual-booting, VirtualBox offers a flexible, cross-platform solution. In this guide, we will walk you through the steps to install VirtualBox on a Linux system.

What is VirtualBox?

VirtualBox is an open-source, cross-platform virtualization software developed by Oracle. It allows users to create and manage virtual machines (VMs) on their physical hardware, enabling them to run multiple guest operating systems such as Windows, macOS, and various Linux distributions. VirtualBox is well-known for its ease of use, versatility, and rich feature set, including snapshots, shared folders, seamless mode, and USB support.

Why Use VirtualBox on Linux?

Cross-platform support: VirtualBox works on Linux, Windows, and macOS.
Open-source and free: The software is free to use for both personal and professional applications.
Versatile OS support: You can run a wide variety of guest operating systems, from older versions of Windows to modern Linux distributions.
Powerful features: Features like shared folders, drag-and-drop, and hardware acceleration make it easy to integrate guest OSes with your Linux system.

Prerequisites

Before we get started, make sure you have:

A Linux machine with root or sudo privileges.
A stable internet connection to download necessary packages.
At least 2 GB of RAM and 10 GB of free disk space (the more, the better).

Step 1: Update Your Linux System

First, it’s essential to ensure your system’s package repositories are up-to-date. Open your terminal and run the following commands:

For Debian/Ubuntu-based distributions:

sudo apt update && sudo apt upgrade

For Fedora or RHEL-based systems:

sudo dnf update

Step 2: Install Required Dependencies

Before installing VirtualBox, there are a few essential packages you’ll need to ensure a smooth installation process. These include the dkms, gcc, and make packages, which help compile VirtualBox’s kernel modules.

For Debian/Ubuntu:

sudo apt install build-essential dkms

For Fedora:

sudo dnf install kernel-devel kernel-headers make gcc dkms

Step 3: Add the VirtualBox Repository

The official VirtualBox package may not always be available in your default Linux repositories, so you’ll need to add the VirtualBox repository to your system.

For Debian/Ubuntu-Based Distributions
First, download and add Oracle’s public key:

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

Next, add the VirtualBox repository to your sources list:

sudo add-apt-repository “deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib”

Update your package list:

sudo apt update

For Fedora-Based Distributions
Fedora users can directly install VirtualBox using the RPM Fusion repository. Run the following command to enable the free and nonfree repositories:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Step 4: Install VirtualBox

Now that you’ve added the necessary repositories, you can proceed to install VirtualBox.

For Debian/Ubuntu-Based Systems
To install the latest version of VirtualBox, run:

sudo apt install virtualbox-6.1

For Fedora-Based Systems
To install VirtualBox on Fedora, run:

sudo dnf install VirtualBox-6.1

Step 5: Install the VirtualBox Extension Pack (Optional)

The VirtualBox Extension Pack provides additional features such as USB 2.0/3.0 support, remote desktop protocol (RDP), and disk image encryption. It’s a great addition if you plan to use advanced features.

To install it, download the Extension Pack from the official VirtualBox website and then run the following command:

sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-.vbox-extpack

Make sure to replace with the correct version number you downloaded.

Step 6: Verify the Installation

After installation, verify that VirtualBox is installed correctly by running:

virtualbox

This should launch the VirtualBox graphical interface.

Step 7: Create Your First Virtual Machine

Now that VirtualBox is installed, you’re ready to create your first virtual machine (VM). Here’s how:

Open VirtualBox from your application menu or by typing virtualbox in the terminal.
Click on “New” to create a new virtual machine.
Follow the prompts to specify the name, operating system type (e.g., Linux, Windows), memory size, and storage allocation for your VM.
Once the VM is created, you can install an operating system by attaching an ISO image of the desired OS.
Step 8: Managing VirtualBox via the Command Line (Optional)
In addition to the graphical interface, VirtualBox can also be managed using the command line with VBoxManage. Here are some basic commands:

List all VMs:

VBoxManage list vms

Start a VM:

VBoxManage startvm “”

Stop a VM:

VBoxManage controlvm “” poweroff

Step 9: Keeping VirtualBox Updated

To ensure that you always have the latest features and security patches, you should periodically check for updates and install them. Here’s how you can update VirtualBox:

For Debian/Ubuntu:

sudo apt update
sudo apt upgrade virtualbox

For Fedora:

sudo dnf upgrade –refresh VirtualBox

Troubleshooting Common Issues

1. Kernel Driver Not Installed (VERR_VM_DRIVER_NOT_INSTALLED)

This error typically occurs if the VirtualBox kernel modules are not compiled correctly. Run the following command to recompile the kernel modules:

sudo /sbin/vboxconfig

2. Failed to Open a Session for the Virtual Machine

Ensure that your user is added to the vboxusers group. You can do this by running:

sudo usermod -aG vboxusers $(whoami)

Log out and log back in for the changes to take effect.

3. VirtualBox GUI Fails to Start

If the VirtualBox GUI fails to start, try launching it from the terminal to see the error messages:

virtualbox

Conclusion

VirtualBox is an excellent virtualization tool for Linux users who want to run multiple operating systems on their machines. With this guide, you now know how to install and configure VirtualBox on various Linux distributions. Whether you are a developer needing to test applications on different platforms or an enthusiast looking to experiment with different operating systems, VirtualBox offers a robust and versatile solution for your virtualization needs.

By following the steps outlined in this guide, you can install and use VirtualBox seamlessly on your Linux machine. Happy virtualizing!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button