How to install Ubuntu Server on VirtualBox

In this tutorial I will show how to install Ubuntu Server on your local Windows machine and how to connect to virtual machine through SSH.

Nowadays having local Linux server is a must for every QA engineer. Local Linux server helps to debug applications, run your tests and install additional utilities which make your life easier. In this tutorial I will show how to install Ubuntu Server on your local Windows machine.  

Install VirtualBox on Windows

First of all, we have to install VirtualBox on local Windows machine. We are going to run Ubuntu Server inside VirtualBox VM. Your Windows machine is considered as host machine and Ubuntu Server as guest machine. To download latest stable version open VirtualBox official website.

VirtualBox home page

Click "Download VirtualBox" image and it will show all available files to download.

From VirtualBox platform packages section you should click "Windows hosts" and after clicking download starts automatically.

Install VirtualBox

Once download is complete open VirtualBox installer file. If you see dialog window with text "Oracle VM VirtualBox 7.0.6 needs the Microsoft Visual C++ 2019 Redistributable Package being installed first" you have to press "OK" button then finish VirtualBox installation.

Oracle VM VirtualBox 7.0.6 needs the Microsoft Visual C++ 2019 Redistributable Package being installed first.

Now you have to download Microsoft Visual C++ 2019 Redistributable Package and install it.

Microsoft Visual C++ 2019 Redistributable Package download page

Make sure you download correct architecture and in case if you don't know, open CMD and type this command

wmic OS get OSArchitecture

Once Visual C++ Package is installed you can proceed with installation of VirtualBox. If everything is fine you should see VirtualBox installation window.

VirtualBox Setup Wizard

Click "Next" and it will ask you which features you would like to install. I recommend leaving everything as it is and click "Next" button again.

VirtualBox Network Interfaces warning

Press "Yes" button if you see warning about resetting network connection.

VirtualBox missing Python dependencies

In a new window press "Yes" button again to agree installation of dependencies. Next you have press "Install" button to start the installation.

VirtualBox Installation

You have to wait until installation if done, once you press "Finish" button it will launch VirtualBox.

VirtualBox installation is done

Download Ubuntu Server LTS version

To install Ubuntu Server with VirtualBox we have to download latest Ubuntu Server LTS version. LTS stands for long term support, and I highly recommend choosing LTS version.    

Ubuntu Server Download page

You have to download ISO file and move to next step once it's done.

Create new virtual machine on VirtualBox

Now we have VirtualBox installed, latest Ubuntu Server ISO file downloaded, and we have to create new virtual machine. Click "New" button to create new virtual machine.

In "Name" field insert any meaningful name, I named it as Ubuntu Server 22.04. Select ISO image you recently downloaded. The rest you can leave as it is.

VirtualBox VM name and ISO image

Open "Unintended Install" section, insert username and password. Make sure Hostname field does not include empty spaces and check mark is displayed next to it. Optionally, you can check "Install in Background" checkbox if you would like to install in background.

Note, "Install in Background" option didn't work for me while installing Ubuntu Server. If it happens to you as well, you should double click on virtual machine to open VM window.

VirtualBox Unattended Install

In Hardware step you can increase RAM and CPU properties based on your local machine capabilities. If not sure, you can leave as it is and change these settings after installation. I increased base memory to 4GB and number of processors to 2.

VirtualBox Hardware settings

In Hard Disk step I recommend only changing disk size, I allocated 50GB for virtual machine.

VirtualBox Hard Disk settings

Now you can press "Finish" button which will start the Ubuntu Server installation.

Install Ubuntu Server on VirtualBox

First step will be to select language.

Ubuntu Server language select

Next you have to select your keyboard layout.

Ubuntu Server keyboard layout

Ubuntu Server comes with two versions, standard and minimized. Minimized version is often used in cloud computing and I would suggest to select it if you are familiar with Ubuntu. If not select standard version.

Ubuntu Server standard and minimized

Do not change network settings and press Done.

Ubuntu Server Network settings

Leave empty proxy address if you are not going to use proxy connection.

Ubuntu Server proxy connection

Use default mirror image, no need to change it. On storage configuration step leave everything as it is and move to next step.

Ubuntu Server storage configuration

Press "Done" button on storage confirmation step and it will display warning message. Select "Continue" and hit the Enter key.

Ubuntu Server storage confirm action
Ubuntu Server storage confirm action

In profile setup insert username and password. It was not supposed to show this step because we already provided required information but seems there is an issue with that.

Ubuntu Server profile setup
Ubuntu Server profile setup

Skip "Ubuntu Pro" option and check "Install OpenSSH server" option. Without OpenSSH server you won't be able to login through SSH connection.

Ubuntu Server OpenSSH Server
Ubuntu Server OpenSSH Server

In next step you can install recommended software, but I prefer to skip this step.

Ubuntu Server featured server snaps
Ubuntu Server featured server snaps

Once you click "Done" button Ubuntu Server installation starts. Installation is going to take some time. When installation is complete you have reboot the VM.

Ubuntu Server installation complete
Ubuntu Server installation complete

Take snapshot of virtual machine

One last thing I would recommend to do is to take a snapshot of virtual machine. Once VM is up and running, you have select Machine -> Take Snapshot.

VirtualBox take snapshot

Insert snapshot name and description, then hit "OK" button.

VirtualBox snapshot name and description
VirtualBox snapshot name and description

VirtualBox will create a new snapshot and if something goes wrong you will be able to restore from this point.

How to SSH to VirtualBox virtual machine

First of all you have to shutdown running VM and open VM settings. In settings select Network -> Adapter 1 and open Advanced settings.

In Advanced settings press "Port Forwarding" button.

Add new forwarding rule and save.

  • Protocol: TCP
  • Host IP: 127.0.0.1
  • Host Port: 2222
  • Guest IP: 10.0.2.15
  • Guest Port: 22

Start the virtual machine.

Connect to VM via SSH protocol

Open CMD and insert this command:

ssh username@127.0.0.1 -p 2222

You have to accept server fingerprint and insert your password to log in. If you see something similar you did everything correctly.

Conclusion

Congratulations, you have just installed Ubuntu Server on your local machine and connected through SSH. Now you can install product you are testing in this server, run your automated tests and experiment. Thanks for reading this tutorial, I hope it was useful.