A photo of Geoffrey Hayward

Notes on Successfully Running Ubuntu in VirtualBox

Published January 26, 2024

And abstract image of programming code surrounded by a light bulb.

As a Software Developer who likes to use Ubuntu for Development but can sometimes only run it as just another window in Windows, I would like to share some nuanced VirtualBox configurations I built up over the years.

Running Ubuntu, VirtualBox has many benefits; for example, when the host computer is Windows, you can have everyday tools like Microsoft Office at your fingertips; plus, I find myself using Regex Buddy a lot, which only runs on Windows.

Here is a set of instructions for installing Ubuntu on VirtualBox, including installing the VirtualBox expansion pack and additional configurations.

Install VirtualBox Expansion Pack

Before you proceed with installing any virtual machines, it’s advisable to install the VirtualBox expansion pack to unlock additional features.

How to Install: Navigate to the VirtualBox downloads page and download the appropriate expansion pack for your version of VirtualBox. Once downloaded, go to File > Preferences > Extensions in VirtualBox and add the downloaded expansion pack.

Creating a VM for Ubuntu

Begin by downloading the latest Ubuntu Desktop ISO from the official website. Where you will also find official guidance on setting up Ubuntu in VirtualBox. However, I have found that the official guidance is not sufficient. In my experience of following it the virtual machine’s screen flickers after install and my user account does not have sudo access. So I have included the steps I follow below.

Create New VM:

  1. In Virtual Box click the “New” button at the top of the window.
  2. Enter a name for your VM.
  3. Select the ISO file you downloaded earlier.
  4. It should then automatically, set the type as “Linux” and version as “Ubuntu” for you based on the ISO.
  5. Select “Skip Unattended Installation” and click “Next” to proceed.

Assign Memory:

  • I recommend you assign 8 GB of memory to your VM. However, if you have less than 16 GB of RAM on your host machine, you may want to assign less.
  • On the same screen, you can also assign CPU cores. I recommend you assign 2 to 4 cores to your VM. I find too many cores can cause the VM to run slowly.
  • Then click “Next” to proceed.

Create a Virtual Hard Disk:

  1. Then Choose “Create a virtual hard disk now”
  2. Assign lots of hard disk space. I don’t find the default 25 GB to be enough, so add as much as you can. I recommend at least 200 GB.
  3. Then click “Create” and finally “Finish”.

VM Settings

Once you have created a VM, but before Ubuntu as been installed, you can adjust the settings. I recommend you adjust the following settings:

  • General > Advanced > Shared Clipboard: Bidirectional This will allow you to seamlessly copy and paste between your host machine and the VM.

  • Desplay > Screen > Video Memory Give it as much as you can. This will allow you to use higher screen resolutions, and it will make the VM run faster without flickering.

  • Shared Folders > Add a new shared folder: Select the folder on your host machine that you want to share. This will allow you to seamlessly access files on your host computer. I normally select my downloads and documents folders.

    • Check the auto-mount option to automatically mount when the virtual machine starts.

Installing Ubuntu

Once you have created the VM and set the VM Settings, you are ready to follow the Ubuntu Installation Walk-through.

  1. From VirtualBox click “Start” to start the VM
  2. Then follow the Ubuntu Installation steps.

I recommend you select the following options when they are presented:

  • Minimal Installation
  • Install Updates

Finishing Steps: Guest Additions

Once you have installed Ubuntu, you should be able to log into it and start using it. However, you will find that the Bidirectional Clipboard and the Shared Folders do not work, and the screen is still a small box. To get things working properly you will need to install VirtualBox’s Guest Additions. Guest Additions provide better integration between the host system and the virtual machine (such as mouse pointer integration, better display resolutions, etc.). But there are a few steps to complete before Guest Additions will install correctly.

Before Installing Guest Additions

Before installing Guest Additions, you’ll need to install some essential Ubuntu packages.

Inside an Ubuntu Terminal run:

sudo apt-get update
sudo apt-get install build-essential gcc make perl dkms

After the installation is complete, a reboot of your virtual machine to apply the changes is needed.

reboot

Install Guest Additions

Now you can install Guest Additions. This will make the screen fit the space correctly, give you options for two way copy and paste, etc.

In the menu bar of the VirtualBox window hosting Ubuntu, go to Devices > Insert Guest Additions CD Image.

A prompt may appear in Ubuntu asking you to run the software on the Virtual CD. If so, click ‘Run’. However if the prompt does not appear, open a terminal and manually mount the CD image.

sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom

cd /media/cdrom
sudo ./VBoxLinuxAdditions.run

After the installation of Guest Additions is complete, a reboot of your virtual machine to apply the changes is needed. Note if sudo ./VBoxLinuxAdditions.run finishes quickly it probably didn’t work and one of the packages in build-essential gcc make perl dkms the could be missing.

reboot

Then when the VM starts up again, go back to the terminal and run the command to make the bidirectional clipboard work:

sudo usermod -aG vboxsf $(whoami)

Reboot System: Once again, reboot your virtual machine to apply the changes.

reboot

Now you can now us all of the settings in VirtualBox, such as two-way copy-paste and the screen resolution should be correct.

Latest Posts

And abstract image of programming code surrounded by a light bulb.

Setting Default Values in GitHub Actions Workflows

October 20, 2023

GitHub Actions is a powerful platform for automating workflows and tasks in your software development process. When creating workflows, you often need to set default values for variables or parameters, especially when certain values are not always going to be provided. In this blog post, let’s explore two techniques to set default values in GitHub Actions workflows, including a handy ! contains() approach and the double pipe || hack. We’ll also discuss the potential limitations of the double pipe hack.

Continue reading
A post style illustration of a slack slash command that shows an Octocat

Triggering a GitHub Actions Workflow with a Slack Slash Command

May 10, 2021

In this post I am going to show how you can trigger a GitHub Actions workflow with a Slack Slash command.

Continue reading