WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Install and Use VirtualBox on Linux

Edited 5 months ago by ExtremeHow Editorial Team

VirtualizationInstallationVirtualBoxOperating SystemsConfigurationVM ManagementHost SetupGuest SetupPerformanceApplications

How to Install and Use VirtualBox on Linux

This content is available in 7 different language

VirtualBox is a powerful open-source virtualization application that allows you to run multiple operating systems simultaneously on your Linux machine. Whether you are a developer, a tester, or just a curious user who wants to try out different operating systems, VirtualBox provides a simple and convenient way to do so. This guide will show you step-by-step how to install and use VirtualBox on a Linux system.

What is VirtualBox?

VirtualBox is a free and open-source virtualization software that enables you to run additional operating systems inside your existing operating system. Created by Oracle, VirtualBox supports the installation of both x86 and AMD64/Intel64 virtual machines. It works on various host systems such as Windows, macOS, and Linux.

Prerequisites

Before we move on to the installation, let’s make sure your Linux system is ready for VirtualBox. Here are some prerequisites:

Step 1: Update your system

Before installing any new software, it is always a good idea to update your system to ensure that all packages are up-to-date. This will also help resolve any potential dependency issues. Open your terminal and run the following command:

sudo apt update sudo apt upgrade

For other distributions, such as Fedora, CentOS, or Arch Linux, you'll need to use the equivalent command, usually using the package manager for your distribution (dnf, yum, or pacman, respectively).

Step 2: Download and install VirtualBox

Using distribution repositories

Most Linux distributions provide VirtualBox in their repositories. You can install it directly using your package manager. For Ubuntu, use:

sudo apt install virtualbox

On Fedora, you would use:

sudo dnf install virtualbox

However, using the distribution repository can sometimes lag behind the latest VirtualBox version. If you want the latest version, consider the following method.

Download VirtualBox from the official website

Oracle's website provides the latest version of VirtualBox for various Linux distributions as DEB and RPM packages. To download:

  1. Visit the VirtualBox Linux download page.
  2. Download the appropriate package for your distribution (DEB for Ubuntu-based systems, RPM for Fedora-based systems).

Installing the downloaded package

Once downloaded, you can install it using the following command:

For DEB-based systems (Ubuntu):

sudo dpkg -i virtualbox-[version]-Ubuntu-[version].deb
sudo apt-get -f install

The first command installs VirtualBox while the second command resolves any dependency issues.

For RPM-based systems (Fedora):

sudo rpm -Uvh VirtualBox-[version]-[Fedora.version].rpm

Setting up Oracle public keys

For some distributions, you may need to set up Oracle's public keys to verify the installation:

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

Step 3: Add your user to the vboxusers group

To be able to use USB devices and other VirtualBox features, you must add your user to the vboxusers group. Do this with the following command:

sudo usermod -aG vboxusers [your-username]

Replace [your-username] with your actual username. Next, log out and log back in for the changes to take effect.

Step 4: Verify the installation

To verify that VirtualBox has been installed correctly, run the following command in your terminal:

vboxmanage --version

This command will display the installed version of VirtualBox, and confirm that it is installed and working.

Step 5: Install the extension pack (optional)

Oracle VM VirtualBox Extension Pack provides additional functionalities such as support for USB 2.0/3.0 devices and VirtualBox RDP. Download the extension pack from here and install it using the following command:

sudo VBoxManage extpack install [path-to-extension-pack]

Make sure to replace [path-to-extension-pack] with the actual path to the downloaded file.

Using VirtualBox

Creating a new virtual machine

To create a new virtual machine, follow these steps:

  1. Open VirtualBox from the terminal by typing virtualbox or by selecting it from the menu of your desktop application.
  2. Click "New" to start the virtual machine creation wizard.
  3. Provide a name for your virtual machine and choose the type and version of the operating system you want to install.
  4. Assign the amount of memory (RAM) to the virtual machine. The system suggests a default value, which you can adjust to suit your needs.
  5. Create a virtual hard drive. You have the option to adjust its size and choose the file type; VDI (VirtualBox Disk Image) is recommended.
  6. Set the virtual hard disk as dynamically allocated or fixed size. For most use cases, dynamically allocated is suitable because it saves space on your real disk.
  7. Review and confirm your settings, then click “Create” to finalize your new virtual machine.

Installing the operating system

After you create your virtual machine, follow these instructions to install your preferred operating system:

  1. Select your newly created virtual machine from the list in the VirtualBox Manager.
  2. Click "Start" to start the virtual machine.
  3. When prompted, insert the operating system's installation media. This can be an ISO image file you downloaded or a physical disc.
  4. Follow the installation instructions as if you were installing the operating system on a physical computer.

Once the installation is complete, the virtual machine will behave just like a real computer, running the installed operating system.

Using snapshots

Snapshots in VirtualBox allow you to preserve the state of a virtual machine at a given point in time. This feature is useful for creating a point to return to before making important changes. To create and restore a snapshot, do the following:

Creating a snapshot

  1. Select your virtual machine in the VirtualBox Manager.
  2. Click the "Snapshot" button in the upper right corner.
  3. Click “Take Snapshot” and provide a name and an optional description for your snapshot to remember what changes it represents.

Restoring a snapshot

  1. Select the snapshot you want to revert to in the "Snapshots" section.
  2. Click "Restore". If necessary, you can choose to create a current snapshot before restoring an earlier one.

Installing guest additions

VirtualBox Guest Editions are special software packages that can be installed inside a virtual machine to improve performance and add features such as shared folders and seamless mouse integration. To install the Guest Edition:

  1. Start your virtual machine and log in to the guest operating system.
  2. In the VirtualBox menu, go to "Devices" and select "Insert Guest Edition CD Image".
  3. Depending on the guest OS, it may automatically prompt you to run the installer. If it doesn't, open the mounted CD and execute the installation script manually.
  4. Follow the on-screen instructions to complete the installation and restart the virtual machine when complete.

Enabling shared folders

Shared folders allow easy file exchange between your host and guest operating systems. To set up shared folders:

  1. With your virtual machine shut down, open your VM’s “Settings”.
  2. Go to the "Shared Folders" section.
  3. Click the "Add" button on the right side of the window.
  4. Select the folder path on your host and choose a folder name that is recognizable by your guest.
  5. Adjust other settings, such as making the folder read-only, if necessary.
  6. Enable “Auto-mount” so that the folder is visible in your guest OS without the need for manual mounting.
  7. Click “OK” to save the settings and start your virtual machine.

Troubleshooting common problems

VirtualBox kernel module issues

If VirtualBox fails to start your virtual machine, sometimes the problem is a kernel module not being loaded. You can force a reload using the following:

sudo /sbin/vboxconfig

Make sure the correct headers are installed for your current kernel version.

3D acceleration issues

Sometimes, enabling 3D acceleration can cause guest systems to behave unexpectedly. If you experience display problems, try turning off 3D acceleration from the VM settings under "Display" → "Screen".

Performance issues

For slow performance, make sure you allocate enough CPU and RAM to your VM. Also, use the guest edition of VirtualBox to further improve performance.

Networking problems

If your VM cannot access the Internet, check the network settings in VirtualBox. A good initial setup is to use the "NAT" network setting, which will share the host computer's Internet connection with the virtual machine.

Conclusion

VirtualBox is a versatile tool that can greatly enhance your productivity and experimentation on Linux. With the steps outlined in this guide, you are now ready to efficiently create and manage virtual environments. Always remember to save a snapshot before making major changes and use the Guest Edition for the best experience.

If you find anything wrong with the article content, you can


Comments