1

I want to install the Oracle Virtualbox by adding a repository with the apt-add-repository command. In order to gain experience in using the apt commands, I would not like to directly modify the sources.list file. I understand I also need to add the key. I found in the Ubuntu manual the following command to insert :

sudo sh -c "echo 'deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free' > /etc/apt/sources.list.d/virtualbox.list" && wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add - && sudo apt-get update && sudo apt-get install virtualbox-5.0

Unfortunately I do not understand what it does. Can anyone "dismantle" this command and give me the separate list of the commands I should use?

hg8
  • 13,462
piscvau
  • 109

1 Answers1

3

When you encounter commands that you don't understand, use manual pages.

This big command can be separated in three main parts :

  1. Adding VirtualBox repository to the system
  2. Register Oracle public keys
  3. Installing Oracle VirtualBox

1. Adding VirtualBox repository to the system

sudo sh -c "echo 'deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free' > /etc/apt/sources.list.d/virtualbox.list"

Let's breack up each part :

sh -c

If you type man sh you will get :

-c               Read commands from the command_string operand
                 instead of from the standard input.  Special
                 parameter 0 will be set from the command_name operand  
                 and the positional parameters ($1, $2, etc.)
                 set from the remaining argument operands.

Now :

deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free  

is the address where the VirtualBox packages are located.

When you run the command lsb_release -cs it will output your Ubuntu version :

$ lsb_release -cs
trusty

> is a redirection operator. It writes the previous output to the following file :

/etc/apt/sources.list.d/virtualbox.list

When you run

echo 'deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free'  

it will output in your terminal :

deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free

Running

echo 'deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free' > /etc/apt/sources.list.d/virtualbox.list  

will write the line :

deb http://download.virtualbox.org/virtualbox/debian '$(lsb_release -cs)' contrib non-free

to the /etc/apt/sources.list.d/virtualbox.list file instead of giving a terminal output.

Note : This is not the advised method to use. It may lead to duplicate entries when running twice.

The recommended way to add the VirtualBox repository to the system is add-apt-repository :

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

Replace trusty with your current Ubuntu version.


2. Register Oracle public keys

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc

man wget output :

DESCRIPTION
       GNU Wget is a free utility for non-interactive download of files from
       the Web

[...]

-q
       --quiet
           Turn off Wget's output.

With this command you download the VirtualBox public key...

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O-  

...and register it to the system (What does the “-” mean?):

sudo apt-key add -

3. Installing Oracle VirtualBox

sudo apt-get update

man apt-get output :

   update
       update is used to resynchronize the package index files from their
       sources. The indexes of available packages are fetched from the
       location(s) specified in /etc/apt/sources.list. 

And finally sudo apt-get install virtualbox-5.0 installs the virtualbox-5.0 package.


If you need additional clarification, do not hesitate to ask.


More information you can find in the answer from @takkat.
There is a list of all separated commands necessary to install VirtualBox.

hg8
  • 13,462
  • Can you do this with apt-add-repository? – Stefano Palazzo Dec 04 '15 at 11:32
  • 2
    @StefanoPalazzo : sudo add-apt-repository "deb http://download.virtualbox.org/virtualbox/debian wily contrib" - Replace wily with the Ubuntu edition you use. :) – cl-netbox Dec 04 '15 at 11:36
  • @StefanoPalazzo I missed this part of the question. I have updated my answer ;) – hg8 Dec 04 '15 at 13:11
  • 1
    Thanl you so much for this help. However on my machine the sudo add-apt-repository seems to create a problem in the apt-get update. I needed to add http:// in front of the download.virtualbox.org/...... – piscvau Dec 04 '15 at 13:32
  • @piscvau Glad it helped you. Yes if you have Ubuntu 14.04 it is the correct command ;) – hg8 Dec 04 '15 at 13:34
  • Don't I have to setup priorities for the Oracle virtual box over the virtual box which is in the Ubuntu ppa? If so How do I do it? – piscvau Dec 04 '15 at 13:36
  • No it is done by default. Ubuntu will use the repository with the highest Virtualbox version (so the Oracle one). – hg8 Dec 04 '15 at 13:38