134

I am a newbie. For some reasons, I need to install Virtualbox. I see that I can easily install it using the Software Center, but I trust most the apt-get install way, because I find it safer, less buggy, and it helps me accommodate more with the Terminal.

So, my question is the following: is there a way to install VirtualBox using the command line? I would prefer something easy, like apt-get install not unzipping, archiving, etc, because I still don't know how to do these in the Terminal.

168

Open a terminal and execute:

sudo apt-get install virtualbox 

which should work.

Once you have installed it you probably want to install guest additions in the guest OS.

Also you probably want the extension pack which you can get from here:

https://www.virtualbox.org/wiki/Downloads

Make sure you get the correct version.

As of Xenial 16.04, you can also get the extension pack from the Canonical repositories. Go to the terminal and execute:

sudo apt install virtualbox-ext-pack 

Therefore, as of Xenial 16.04, you should be able to get virtualbox and the extension pack by typing the following:

sudo apt install virtualbox virtualbox-ext-pack 

Following the instructions on your screen.

To install the user interface to manage your virtual boxes use this command

sudo apt install virtualbox-qt
  • 1
    @ Warren Hill - Thanks a lot! To be frank, I have used the easier path - just sudo apt-get install virtualbox - without looking for the correct version. Till now, it works fine. But next time when I will need to install it, I'll be wiser and I'll follow your advice. :-) – Cristiana Nicolae Oct 28 '13 at 14:16
  • 2
    Ubuntu 15.04 cloud image - no installation candidate found for virtualbox. This worked last week. Here is a paste: pastebin.com/dYkSY3jc The virtualbox meta-package is not available on my Ubuntu15.04 cloud images so I have to add the repo and update first. – spyderdyne Nov 17 '15 at 19:25
  • 1
    This doesn't work anymore. See askubuntu.com/a/713526/235667 answer. – Vadorequest Sep 11 '16 at 19:21
  • I had to install virtualbox-qt as well, for virtualbox to work on the command line and for it to appear in my system menu. – Michael Scheper Jul 1 '17 at 0:08
  • It should be noted that Ubuntu 16.04 LTS and VirtualBox prior to 5.2 no longer work together. Currently, Ubuntu is shipping VirtualBox 5.0.40 which crashes the whole system. See bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1736116 for details. – Stephen M Feb 22 '18 at 18:17
38

If you want to have a latest version of VirtualBox, check this: https://www.virtualbox.org/wiki/Linux_Downloads

Add one of the following lines according to your distribution to your /etc/apt/sources.list:

deb http://download.virtualbox.org/virtualbox/debian xenial contrib
deb http://download.virtualbox.org/virtualbox/debian trusty contrib
deb http://download.virtualbox.org/virtualbox/debian precise contrib

Alternatively, you can use add-apt-repository to add to your /etc/apt/sources.list:

sudo apt-add-repository "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib"

Add secure key:

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

- or for Debian 8 ("Jessie") / Ubuntu 16.04 ("Xenial") and later:

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

Install VirtualBox:

sudo apt-get update
sudo apt-get install virtualbox-5.2
  • 2
    Curious if you can elaborate on why this is preferable to sudo apt-get install virtualbox and why you can't just run sudo apt-get install virtualbox-5.0? – Luke Jul 22 '16 at 20:48
19

You can use

apt-cache search virtualbox

to search for packages related to "virtualbox".

Among others this finds a package virtualbox. Use

apt-cache show virtualbox

to get more information about that package.

As the description sounds like what you want use

sudo apt-get install virtualbox

to install the package.

8

Run these commands to install Virtualbox 5.0.

sudo apt-add-repository "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib"
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install virtualbox-5.0 dkms 

dkms (optional): "Ubuntu/Debian users might want to install the dkms package to ensure that the VirtualBox host kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are properly updated if the linux kernel version changes during the next apt-get upgrade."

  • 1
    Note: Latest is now 5.1 This is the way to go now, and should be the accepted answer. – Vadorequest Sep 11 '16 at 19:21
  • This is a good answer but you need to refer to virtualbox.org/wiki/Linux_Downloads to make sure you have the correct versions. Both the keys and virtual box versions listed here are out of date. – Harlan Nelson May 3 '18 at 18:12
3

My Ubuntu-15.04 cloud images are missing the virtualbox package from the included sources. Kostanos' method works, but since virtualbox is a meta-package with multiple versions depending on the release you are running you may need to specify a particular version.

Here is a script that checks for an installation candidate, installs the repo if there isnt one, then updates the package lists and installs it for you. As noted in his answer, be sure to change "vivid" to your release name.

#!/bin/bash
if [ $(dpkg-query -W -f='${Status}' virtualbox 2>/dev/null | grep -c "ok installed") -eq 0 ];
  then
    if [ $(apt-cache search virtualbox | grep virtualbox) ];
      then
        apt-get install -y virtualbox
      else
        apt-add-repository "deb http://download.virtualbox.org/virtualbox/debian vivid contrib"
        wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | apt-key add -
        apt-get update
        apt-get install -y virtualbox-5.0
    fi
fi

I had to write this for a Mythos project automation so I thought I would share.

Thanks.

3

according to Oracle Official Doc for Linux Download you can install virtual box by adding it's repository using two ways

1 - add it's repository(according to your ubuntu version) directry into /etc/apt/sources.list file [next line for ubuntu 16.04 xenial repositty]

deb http://download.virtualbox.org/virtualbox/debian xenial contrib

2 - adding it's repository using command line [next line for ubuntu 16.04 xenial repositty]

sudo apt-add-repository "deb http://download.virtualbox.org/virtualbox/debian xenial contrib"

Notice:for another ubuntu version use the same repository But change xenial word with your ubuntu version name

deb http://download.virtualbox.org/virtualbox/debian {ubuntu-version-name} contrib

Then add Oracle public keys by copy key from oracle_vbox_2016.asc , oracle_vbox.asc and paste them into two files oracle_vbox_2016.asc, oracle_vbox.asc finally add them into your system

sudo apt-key add oracle_vbox_2016.asc
sudo apt-key add oracle_vbox.asc

Another way to adding Oracle public keys using command lines

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 -

after last two steps, you need to install virtual box using apt-get install command line:

sudo apt-get update
sudo apt-get install virtualbox-5.1

you can install virtual box manually By download it's dab packages which exists into Oracle Official Doc for Linux Download Example: download link for Ubuntu 16.04 xenial 64 bits dab package

Notices answer of @Kostanos same as my answer but install virtualbox-5.0 also for more link for installing virtual box

protected by Community Feb 19 '16 at 3:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.