Install GCC 7 on Ubuntu?

39,095

Solution 1

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

sudo add-apt-repository ppa:jonathonf/gcc
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

Solution 2

Ubuntu 18.04 has both GCC 7 (7.3.0-16ubuntu3, at the moment I am writing this answer) and GCC 8 (8-20180414-1ubuntu2). There isn't anymore the need of adding third-party repositories: Just run sudo apt-get install gcc-7.

Share:
39,095

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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
    
    • Admin
      Admin almost 7 years
      The ubuntu-toolchain-r/test PPA does not appear to provide gcc-7 for Ubuntu 16.10 (Yakkety) - although it does for both 16.04 (Xenial) and 17.04 (Zesty) - as you can see by visiting “PPA for Ubuntu Toolchain Uploads (restricted)” team and filtering by series
    • Admin
      Admin almost 7 years
      Thanks Steeldriver. Expanding the caret labeled "Technical details about this PPA" seems to show its available for 16.10. Weird... I think I'll put this bug report on hold until we can find a distro that provides GCC 7.
    • Admin
      Admin almost 7 years
      The PPA is available for 16.10, but it does not provide the all the same packages - possibly because 16.10 is not an LTS release
    • Admin
      Admin almost 7 years
      For those who can't get this to work (like me), also see How can I undo adding a PPA and installing packages from it? on Ubuntu Stack Exchange.
  • Admin
    Admin almost 7 years
    Thanks GAD3R. Do you know who jonathonf is? I'm trying to use Ubuntu's gear because its already trusted. Otherwise, I have to jump through the hoops of figuring out who jonathonf is, and determine if he is a trustworthy source.
  • Nathan B
    Nathan B about 6 years
    Should it work for linaro as well?
  • Phi
    Phi almost 3 years
    Command is now sudo add-apt-repository ppa:jonathonf/gcc, without the trailing -7. You can also get other GCC versions from the repo. Don't forget the apt update!
  • GAD3R
    GAD3R almost 3 years
    @Phi Thank you for this update