How to install gcc-7 or clang 4.0?

Super mega GCC table for all Ubuntu versions: How do I use the latest GCC on Ubuntu?

Ubuntu 16.04 and below

There is an official Ubuntu GCC test PPA which should be preferred:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7 g++-7
gcc-7 --version

GCC 7 was release in May 2017, so too late for 17.04 main release.

The PPA does not currently have GCC for newer releases e.g. 16.10, only LTS 12.04, 14.04 and 16.04, as can be seen at: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test | snapshot. I think it had 17.04 previously but it was removed? See also: https://unix.stackexchange.com/questions/371737/install-gcc-7-on-ubuntu

Tested on Ubuntu 16.04, October 2018.

Ubuntu 17.10 and above

Has GCC 7.2 and clang 4 by default! https://packages.ubuntu.com/artful/gcc | https://packages.ubuntu.com/artful/clang

$ gcc --version
gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0
$ clang --version  
clang version 4.0.1-6 (tags/RELEASE_401/final)

GCC 8 on 16.04

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-8 g++-8
gcc-8 --version

gives 8.1.0 as of 2018-11.

Default in Ubuntu 18.04:

  • Install gcc-8 only on Ubuntu 18.04?
  • https://packages.ubuntu.com/bionic/gcc-8

Crosstool-NG

If you are really serious about this, compile and use your own GCC with Crosstool-NG as explained at: https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/52454603#52454603

This will allow you to use a wide variety of GCC versions on a wide variety of Ubuntu versions without downloading blobs from PPAs you don't necessarily trust.


You can already install gcc-7 and g++-7 from this package.

sudo add-apt-repository ppa:jonathonf/gcc-7.1
sudo apt-get update
sudo apt-get install gcc-7 g++-7