How to Install Oracle Virtual Box 5.2 on Ubuntu 16.04, 17.10 (Xenial / Trusty / Artful) and 18.04 (bionic)

Oracle VM VirtualBox is a free and open-source hypervisor for x86 and AMD64/Intel64 computers currently being developed by Oracle Corporation. A VirtualBox or VB is a software virtualization package that installs on an operating system as an application. VirtualBox allows additional operating systems to be installed on it, as a Guest OS, and run in a virtual environment.

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise  customers, it is also the only professional solution that is freely  available as Open Source Software under the terms of the GNU General  Public License (GPL) version 2. VirtualBox runs on Windows, Linux, Macintosh, and Solaris hosts and supports a large number of guest operating systems including windows. VirtualBox is being actively developed  with frequent releases and has an ever growing list of features,  supported guest operating systems and platforms it runs on.

So in order to install Virtual box on your Ubuntu system, follow the below steps :

1. Setting-up  APT repository :

To update the apt repository you need to know what version of ubuntu you have installed. For this run the below command :
 cat /etc/lsb-release
Output :
 $ cat /etc/lsb-release 
In my case i have installed ubuntu 16.04 xenial. So according to your version add the following line to  '/etc/apt/sources.list' file.

For Ubuntu 16.04 Xenial
 deb xenial contrib
For Ubuntu 14.04 Trusty
 deb trusty contrib
For Ubuntu 17.10 Artful
 deb zesty contrib
For Ubuntu 18.04 bionic
 deb bionic contrib
Now to add the repository in sources.list file first open it with nano editor
 sudo nano /etc/apt/sources.list
Now scroll down to the bottom of the page and paste one of the above given repository according to your version of ubuntu. Now press Ctrl + O to save the file and then press Ctrl + X to exit to the nano editor.

2. Import VirtualBox Package Sign Key :

After adding the required apt repository, we need to download and import the Oracle public key for apt-secure using below commands.
 $ wget -q -O- | sudo apt-key add -
 $ wget -q -O- | sudo apt-key add -

3. Install Virtual Box

After the completion of above steps, our system is ready to install virtual box. Now install virtual box with below commands :
 sudo apt-get update
 sudo apt-get install virtualbox-5.2
Now to launch Virtual box just type virtual box on search box, and click on it.

Or type virtualbox on terminal
 $ virtualbox

Conclusion :

In this post we saw the basic installation steps for Oracle VirtualBox in Ubuntu OS. To install Virtual box in windows, you just need to download and install the binary installation setup for windows and run it. Download link :