Ubuntu – Install GCC 7 on Ubuntu

aptgccppaUbuntu

I'm trying to run a test under GCC 7. According to How to install gcc-7 or clang 4.0? on Ubuntu.SE, we can perform the following to install GCC 7 on Ubuntu:

add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update && apt-get install -y gcc-7

The command fails at the install:

# apt-get install -y gcc-7
...
E: Unable to locate package gcc-7

And trying 7.1:

# apt-get install -y gcc-7.1
...
E: Unable to locate package gcc-7.1
E: Couldn't find any package by glob 'gcc-7.1'
E: Couldn't find any package by regex 'gcc-7.1'

According to List all packages from a repository in ubuntu / debian on Server Fault, we can search a particular repo for a package with:

# grep ^Package: /var/lib/apt/lists/ppa.launchpad.net_*_Packages | grep gcc-7
#

But I am not sure if the command above is searching ppa:ubuntu-toolchain-r.

I kind of pieced things together, but they are not working as expected. Either the Ubuntu.SE answer is wrong, the Server Fault search is failing, or I am doing something wrong.

(I don't have a Debain 8 machine available for gcc-7 package, and Fedora 25 appears to lack GCC 7. So I am pretty much stuck with Ubuntu).

What am I doing wrong? Or, how can I install GCC 7?


# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.10
Release:        16.10
Codename:       yakkety

Best Answer

To install gcc-7 on ubuntu you should use this ppa:

sudo add-apt-repository ppa:jonathonf/gcc-7.1
sudo apt-get update

Then run: apt-cache search gcc-7

sample output :

gcc-7-base - GCC, the GNU Compiler Collection (base package)
gcc-7 - GNU C compiler
gcc-7-multilib - GNU C compiler (multilib support)
gcc-7-plugin-dev - Files for GNU GCC plugin development.
gcc-7-test-results - Test results for the GCC test suite
lib32gcc-7-dev - GCC support library (32 bit development files)
libgcc-7-dev - GCC support library (development files)
gcc-7-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-7-hppa64-linux-gnu - GNU C compiler (cross compiler for hppa64)
gcc-7-locales - GCC, the GNU compiler collection (native language support files)
gcc-7-source - Source of the GNU Compiler Collection
libx32gcc-7-dev - GCC support library (x32 development files)
gcc-7-offload-nvptx - GCC offloading compiler to NVPTX
lib64gcc-7-dev - GCC support library (64bit development files)

Install gcc-7:

sudo apt install gcc-7
Related Question