How do I install g++-7 on Ubuntu?
Solution 1:
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:
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.