Why did apt-get install Virtual Box instead of g++?

The command

sudo apt-get install g++ 5.0 

indicates you want to install two packages: g++ and 5.0. (Package names don't have spaces, and apt-get accepts multiple package names, separated by spaces.)

What probably happened is that it installed g++ as requested, then installed all packages (including version numbers) that match the regular expression 5.0 (since there's no package actually named 5.0). (thanks @edwinksl!)

To avoid this, make sure you have the correct package names, without spaces. You can also use the -s option to simulate an apt-get action before doing it for real:

sudo apt-get -s install g++ 5.0

will show you the actions that the command would perform, without actually installing anything. If it looks OK, you can remove the -s to perform the installation.

You could also consider using a more newbie-friendly graphical package manager, such as synaptic or muon.


The correct command to install g++ version 5.x is:

sudo apt-get install g++-5

This will install g++ version 5.3 on xenial, which is the current default (so apt-get install g++ installs it as well, but this will change in the future). In fact, there is no public 5.0 release of GCC. Other g++ releases are packaged, e.g. g++-4.9 or g++-6, which can be installed in the same way.

If you ever need to install a specific (existing) release of g++ which is not packaged for your system, you'll have to build it from sources.