How to install VirtualBox guest additions on Ubuntu 22.04 VM command line?

Here is a quick installation guide for installing VirtualBox Guest Addition ( Oracle VirtualBox extension pack ) on Ubuntu 22.04 VirtualBox VM.

What are VirtualBox Guest addition packages?

VirtualBox guest additions are software tools, to be installed in the guest VM after the OS has been installed. They consist of device drivers and system applications that improve the guest VM performance and usability. They enable several features such as drag and drop, shared folders, changing screen resolutions, copy-paste clipboards, automated logins, and so on. Please refer to the complete guide here: https://www.virtualbox.org/manual/ch04.html

Step #1: Preparing your Ubuntu VM with the required packages

Firstly, you would require to install some dependency packages:

  • gcc
  • make
  • perl

Install all those pre-requisites using the single command below,

sudo apt-get install gcc make perl

Enter your user password and give y when prompted for confirmation to continue.

Step #2: Insert the guest addition CD image

From your VirtualBox VM window, go to Devices Menu and Click on Insert the guest addition CD image

This will mount the VirtualBox guest addition Virtual CD Disk to your Ubuntu Guest OS.

Step #3 Running the installer

  1. Open a command-line terminal
  2. Run the command sudo su –
  3. Enter the password, when prompted
  4. Run the command: bash /media/YOUR-USERNAME/VBox_*/VBoxLinuxAdditions.run (given below)
  5. After installation, reboot the system.
# Run it as root user
#
# sudo su -
#
# Replace YOUR-USERNAME with your ubuntu login name
#

bash /media/YOUR-USERNAME/VBox_*/VBoxLinuxAdditions.run

If you are unsure of the above-mentioned path, try the command: df -kh | grep VBox

In this case, your script path would be:


bash /media/devops/VBox_*/VBoxLinuxAdditions.run

Reboot your system to make these changes in effect.

VirtualBox Guest Addition features

You have successfully installed the guest addition software. With this, you will have some handy features like:

  • Enabling Shared-Clipboard – copy-paste between guest and host ( Detailed guide to enable copy paste )
  • Enable Drag and Drop – you would be able to drag and drop files between guest and host
  • Set custom screen resolution for the Ubuntu Guest (shown in the below image)

FAQs

FAQ: Installing guest addition on VirtualBox Ubuntu Desktop

All these steps will work on the Ubuntu command line, tested using Ubuntu-22.04-desktop-amd64

FAQ: Installing guest addition on VirtualBox Ubuntu Server

VirtualBox Ubuntu server installation may not require the guest additions, if you need them for any specific reason, the steps given above should work.

FAQ: Installing guest additions in older versions of Ubuntu, such as Ubuntu 20.04?

Codetryout has another page explaining the steps required for VirtualBox guest additions on Ubuntu 20.04 VM

FAQ: How to enable Clipboard copy-pastes between Virtualbox Host and guests?

We have an experiment explaining this, please refer to How to enable copy-pastes in Virtualbox Ubuntu VM

FAQ: How to enable files or folders copy-pastes between Virtualbox Host and guests?

Yet again, we have another experiment explaining this, please refer to the guide: How to enable files to drag and drop in a VirtualBox running Ubuntu Linux?