56

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.

1

2 Answers 2

100

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
8
  • 31
    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, 2019 at 15:53
  • 12
    To make @JHBonarius 's useful comment complete, you need to install g++ along with gcc, i.e. sudo apt install gcc-9 g++-9 Feb 3, 2020 at 23:02
  • @JHBonarius: What does your command do? Apr 16, 2020 at 12:42
  • 5
    @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, 2020 at 14:01
  • 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 2, 2020 at 15:35
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
14
  • Thanks for the clarification. I changed PPA to "repository" accordingly.
    – tinlyx
    May 3, 2019 at 11:09
  • Edited my answer and removed info about PPAs and repositories (to be more neutral).
    – N0rbert
    May 3, 2019 at 12:16
  • 1
    Note: you need to sudo apt-get update before the install. Sep 27, 2019 at 22:29
  • 1
    @ZhengQu Yes, it appears that's another thing that changed in 18.04. I was running 16.04 at the time. Feb 1, 2020 at 21:58
  • 1
    This now gives me E: Unable to locate package gcc-9 on Debian GNU/Linux 10 (buster) Aug 16, 2021 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.