How can I install g++-7 on Ubuntu? I did

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Then I can find g++-5, g++-6 packages, but not g++-7. What problems may I encounter when using g++-7? When will it be officially released?

up vote 3 down vote accepted

The repository method alone does not work because you are not using Ubuntu 17.04 (Zesty), which is the release for which the package was built, as you can see in the ppa:

enter image description here

The easiest alternative is to "pin that package" (this is, to tell your Ubuntu to accept a package that is not build for your version). To do so, open a terminal, and type:

sudo nano /etc/apt/preferences

Then, copy to it the following:

Package: gcc-7
Pin: release n=zesty
Pin-Priority: 990

Finally, save the file (press Ctrl+X and then Y).

Now, after a sudo apt-get update, install with sudo apt-get install gcc-7. It should install all required dependencies too.

Note: as a development package, it might require newer libraries which your current Ubuntu version does not have. This might break some packages.

As an alternative to the above method, you can build the package from the source yourself. Get the source files from here. Compile following these instructions.

On this website, you can search GCC- added by Matthias Klose on 2016-12-17. G++ should come with GCC package. Also you should know GCC 7 is still in development.

  • I did just what is written in that website, I added their PPA. But I still cannot find package named gcc-7 or g++-7 – Aleksandr Tukallo Dec 22 '16 at 16:28
  • Commands I do: sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install gcc-7 The result is "Unable to locate package". It seems really strange for me, because gcc-7 package is mentioned on the site you gave. I will be really grateful for your help! – Aleksandr Tukallo Dec 22 '16 at 16:32
  • When you help how to solve the problem, obviously, I'll mark your answer as correct – Aleksandr Tukallo Dec 23 '16 at 11:41
  • Have you tried sudo apt-get update before searching? Also try apt-cache search gcc before running installation. – Faisal Aslam Dec 24 '16 at 15:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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