When you encounter commands that you don't understand, use manual pages.
This big command can be separated in three main parts :
- Adding VirtualBox repository to the system
- Register Oracle public keys
- 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.
Ok. Thanks to Thomas W. for comments that led me to the solution.
The cause seems to trace back to broken packages. I had previously searched how to fix broken packages, but none of the solutions fixed the whole problem. I searched instead for the Hash Sum mismatch error I was getting at the end of apt-get update, and found this solution, that solved the problem.
Answer copied here for completeness:
Remove the content of /var/lib/apt/lists directory:
sudo rm -fR /var/lib/apt/lists/*
then run:
sudo apt-get update
Apparently, and you gurus can correct or elaborate, the clean and autoclean flags for apt-get didn't completely purge the problem children from apt/lists directory.
Best Answer
I have followed this instructions, and it worked great for me (Ubuntu 20.04).
In command line, type this
Then, edit this line by removing the #