Ubuntu – Problem installing g++ ccompiler on Ubuntu 14.04

g++gcc

I tried to install g++ using packages from another user. offline..but there were errors.
After connecting to the net I tried to install using sudo apt-get install g++, but it gave the following output:

gstreamer0.10-alsa is already the newest version.
qtdeclarative5-ubuntu-ui-extras-browser-plugin is already the newest version.
python-gconf is already the newest version.
gstreamer0.10-tools is already the newest version.
libglib2.0-0 is already the newest version.
gir1.2-peas-1.0 is already the newest version.
libatk-bridge2.0-0 is already the newest version.
gnome-session-bin is already the newest version.
libgomp1 is already the newest version.
libmessaging-menu0 is already the newest version.
usb-creator-gtk is already the newest version.
libgnome-desktop-3-7 is already the newest version.
software-properties-gtk is already the newest version.
gnome-control-center-shared-data is already the newest version.
unity-scope-gourmet is already the newest version.
libcupsimage2 is already the newest version.
growisofs is already the newest version.
libjson-glib-1.0-common is already the newest version.
activity-log-manager is already the newest version.
libio-string-perl is already the newest version.
qtdeclarative5-qtfeedback-plugin is already the newest version.
gnome-power-manager is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

and many more lines like this….but g++ is still not installed

Best Answer

Apparently apt-get doesn't know about gcc.

If apt-get knows about a package whose name is g++, it won't attempt to to interpret g++ as anything but the name of a single package. (In contrast, I can reproduce the behavior you're seeing by attempting to install the similarly named nonexistent package q++.)

There are two likely causes of apt-get not knowing about the g++ Install g++ package:

  1. No software source providing g++ package is configured to be used.
  2. A software source providing g++ is configured to be used but the information about what packages are available for installation hasn't been updated since then.

If it were the second reason, you could just run sudo apt-get update. But I think it's more likely the first one.

Make sure main is enabled.

g++ is provided in the main repository component. This should pretty much always be enabled, but perhaps it is not.

Many of the packages necessary for a working Ubuntu system are provided by the main component (this is the software maintained directly by Canonical rather than by the larger community, and it consists mostly of core software important to many Ubuntu systems). Furthermore, some of the packages apt-get listed as installed, such as python-gconf, are in main.

So I think what happened was that main got disabled recently, probably by accident. apt-get knows about software from main that is currently installed because it can see that it's installed. But if main is disabled, apt-get doesn't know about any software from main that you don't have.

To check if main is enabled, and re-enable it if it's not, open Software & Updates (called Software Sources on previous versions of Ubuntu). One way to open this is to click the Settings... button in the Software Updater (called the Update Manager in old versions of Ubuntu).

Then make sure the box labeled "Canonical-supported free and open-source software (main)" is checked.

enter image description here

If it already was, then most likely I have guessed wrong about the cause of your problem. If it was not already checked, check the box (you may need to enter your password) and click Close. You'll be told "The information about available software is out of date"; click the Reload button.

enter image description here

Then try installing g++ again.

Try a different APT mirror.

If the main component was already enabled, maybe there's something wrong with the APT mirror you're using. Especially if you're not using one of the official mirrors (us.archive.ubuntu.com, with us replaced with your "country code"), I recommend trying a different mirror, an official one if possible.

You can set your APT mirror in Software & Updates as well. Just change it in the drop-down menu labeled "Download from".

enter image description here

As when enabling a software source, when you quit Software & Updates after changing your download server, you'll be prompted that software information is out of date and you should click Reload. Then see if g++ can be installed.

Further troubleshooting.

If it still can't be installed, then you should edit your question with more information to help troubleshoot the problem.

  • Provide the contents of /etc/apt/sources.list. One way to do this is to copy the complete output of the command cat /etc/apt/sources.list and paste it into your question. Select it and press Ctrl+K to format it properly.
  • Optionally, you might want to see if you can find and install the g++ Install g++ package in the Software Center. If you can, great! More likely, maybe doing so will reveal some information useful to figuring out what's wrong.
Related Question