62

gcc-9 is just released.

I was wondering if there is a repository that allows me to install gcc 9 on Ubuntu 18.04 LTS (bionic)?

There seems to be repositories supporting disco:

https://packages.ubuntu.com/disco/gcc-9-base

But I liked to have it on the current LTS for a while.

N0rbert
  • 99,918
tinlyx
  • 3,230

2 Answers2

112

It is now available in ubuntu-toolchain-r too:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-9

If the add-apt-repository command cannot be found, run this:

sudo apt install software-properties-common

Above commands install just c compiler, if you need c++ compiler (g++) too

sudo apt install g++-9
ISanych
  • 1,236
  • 36
    just as a reminder to people reading this sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 – JHBonarius Oct 25 '19 at 15:53
  • 13
    To make @JHBonarius 's useful comment complete, you need to install g++ along with gcc, i.e. sudo apt install gcc-9 g++-9 – user1507435 Feb 03 '20 at 23:02
  • @JHBonarius: What does your command do? – Tor Klingberg Apr 16 '20 at 12:42
  • 6
    @TorKlingberg, apt install gcc-9 g++-9 installs binaries with names gcc-9 and g++-9 in Ubuntu 18.04, if you want to use gcc & g++ then update-alternatives provides convenient way to do it. And if you have multiple different versions of gcc (and not just gcc) you can create alternatives for all of them and then easily switch between them. – ISanych Apr 16 '20 at 14:01
  • Not working on Bionic : ```The following packages have unmet dependencies: gcc-9-multilib : Depends: libc6-dev-i386 (>= 2.11) but it is not going to be installed Depends: libc6-dev-x32 (>= 2.11) but it is not going to be installed lib32gcc-9-dev : Depends: lib32gcc-s1 (>= 9.3.0-11ubuntu0~18.04.1) but it is not going to be installed (...) libx32gcc-9-dev : Depends: lib32gcc-s1 (>= 9.3.0-11ubuntu0~18.04.1) but it is not going to be installed (...) E: Unable to correct problems, you have held broken packages.
    
    
    – Henrique de Sousa Nov 02 '20 at 13:16
  • 1
    @HenriquedeSousa, I've just tested it in docker, still installing fine. Either you have something else conflicting installed or something wrong with your packages db. – ISanych Nov 02 '20 at 15:35
  • Yep, I add to use aptitude to force the installation, then it worked. apt alone would not install it. – Henrique de Sousa Nov 02 '20 at 23:35
  • I upgraded my kernel to 5.3.0-050300-generic and VM multiplayer required this version of gcc, it worked like a charm! – Manuel Lazo Jan 11 '22 at 14:21
13

I used a search for PPAs, using search on launchpad.net and found JonathonF's GCC 9.0 PPA. You can install this package by:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:jonathonf/gcc
sudo apt-get update
sudo apt-get install gcc-9
N0rbert
  • 99,918