How do I use the latest GCC on Ubuntu? (Ubuntu 18.04; gcc 8.1)

19,015

The package name is gcc-8, not gcc-8.1, so try:

sudo apt-get install gcc-8 g++-8

As others mentioned, make sure you've added the toolchain test PPA:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
Share:
19,015

Related videos on Youtube

Antonio Perez
Author by

Antonio Perez

Updated on September 18, 2022

Comments

  • Antonio Perez
    Antonio Perez over 1 year

    Ubuntu currently provides gcc version 7.3, however gcc version 8.1 is currently available. I'd like to install gcc 8.1 alongside gcc 7.3 (so that if I call c++ it invokes the version from gcc 7.3, and if I call c++-8 it invokes the version from 8.1).

    I tried following the instructions outlined in this question (but replacing 4.9 with 8.1), but gcc 8.1 isn't in the repository listed in the question:

    $ sudo apt-get install gcc-8.1
    [sudo] password for sky: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package gcc-8.1
    E: Couldn't find any package by glob 'gcc-8.1'
    E: Couldn't find any package by regex 'gcc-8.1'
    

    How do I install gcc 8.1 in ubuntu 18.04?

    Edit: This question isn't a duplicate because GCC updated the way versions are handled. It's now necessary to write sudo apt-get install gcc-8 instead of sudo apt-get install gcc-8.1.

    • steeldriver
      steeldriver almost 6 years
      Did you follow the complete instructions - including adding the appropriate toolchain-r PPA and then updating?
    • muru
      muru almost 6 years
      Did you also read the part which says: "For GCC 5.X or 6, the packages (and correspondingly, the commands) are just called gcc-5, gcc-6, etc. This is due to the change in GCC's version scheme, where 5.1 is the first GCC 5 release, and future 5.X releases are for bug fixes."?
    • muru
      muru almost 6 years
      "This question isn't a duplicate because GCC updated the way versions are handled. It's now necessary to write sudo apt-get install gcc-8 instead of sudo apt-get install gcc-8.1"? Eh, what? It seems you didn't read the accepted answer or my comment here that repeated the relevant parts of that answer.
  • Antonio Perez
    Antonio Perez almost 6 years
    Thank you! I'm glad it's similar; I hadn't realized the package naming system was differ.nt
  • automorphic
    automorphic over 5 years
    sudo apt install g++-8 also installs gcc-8