The recommended way

Ubuntu 23.04 has both the packages you seem to need and in the versions that you require i.e. gcc-13 and gcc-13-aarch64-linux-gnu in the [security] [universe] repository and Ubuntu 23.10 has them in the [main] repository ... So, my advice would, naturally, be to upgrade your system to Ubuntu 23.04 or even 23.10 and then install your desired packages like so:

sudo apt update && sudo apt install gcc-13 gcc-13-aarch64-linux-gnu

That is the recommended and safest way.

The hacky way

Otherwise, it's the on your own risk way ... e.g. adding a PPA such as you did ... Yep, you have already chosen the "on your own risk way" ... Read this (emphasis is mine):

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:ubuntu... to your system's Software Sources.

... that text is quoted from the Launchpad link you included in your question and it's not limited to that specific PPA (which might be of good reputation), but it is what it is.

That PPA enables for installing the package gcc-13 on Ubuntu 22.04 by essentially including that package with its dependencies that can not be satisfied from the Ubuntu 22.04 official repositories and of course some other work might be involved like modifying post-install and/or pre-install scripts and ensuring none of the added package or its dependencies will conflict with existing essential system packages and so forth.

In the case of gcc-13 and gcc-13-aarch64-linux-gnu, which are also made available in Ubuntu 23.04/23.10 official repositories, one might ponder the possibility of installing them from 23.04/23.10 repositories on an Ubuntu 22.04 system? ... Well, yeah surely possible (for these two) and it should make the "on your own risk" zone a bit more appealing as those repositories are official and trusted, but the unsupported part will still apply.

Anyway, I have quickly traced those two packages and their dependencies and then installed both from the official repositories of Ubuntu 23.10 on an Ubuntu 22.04 system successfully without any noticeable drawbacks AFAIK ... After all the GNU C compiler is not essential to the functionality of Ubuntu and is offered as an optional package for manual install.

However, there is probably most likely certainly an extremely big problem awaiting if you're not careful enough i.e. you must make sure no other packages from that repository get installed by any means including automatic-updates so turn all those off and fully update your system first, then follow all instructions precisely (still on your own risk of course) ... If other packages got installed, they might break your system so dangerously badly and possible beyond any applicable repair and of course this is as unsupported as your PPA installed packages ... So, we will not provide any support for either.

Needless to say that I don't prefer it or like it this way, but you seem to need it so I wrote it.

The idea is, basically, to add the official Ubuntu repository containing those two packages, refresh the local cached sources list, install those two packages and promptly delete the added repository from you system like so:

First, add the repository:

echo "deb http://cz.archive.ubuntu.com/ubuntu mantic main" |
sudo tee /etc/apt/sources.list.d/temporary-repository.list

Second, update package lists:

sudo apt update

Third, only install gcc-13 and gcc-13-aarch64-linux-gnu:

sudo apt install gcc-13 gcc-13-aarch64-linux-gnu

Fourth, delete that temporary repository:

sudo rm /etc/apt/sources.list.d/temporary-repository.list

Finally, update your cached packages lists:

sudo apt update

Notice

  • You might need to first remove the gcc-13 package you have already installed from that PPA and the PPA itself to avoid possible dependency version mismatch.

  • You'll need to run those by version number i.e. gcc-13 -v and aarch64-linux-gnu-gcc-13 -v and not just gcc or you can use the Ubuntu alternatives system to choose the default version.

Answer from Raffa on askubuntu.com
Top answer
1 of 1
10

The recommended way

Ubuntu 23.04 has both the packages you seem to need and in the versions that you require i.e. gcc-13 and gcc-13-aarch64-linux-gnu in the [security] [universe] repository and Ubuntu 23.10 has them in the [main] repository ... So, my advice would, naturally, be to upgrade your system to Ubuntu 23.04 or even 23.10 and then install your desired packages like so:

sudo apt update && sudo apt install gcc-13 gcc-13-aarch64-linux-gnu

That is the recommended and safest way.

The hacky way

Otherwise, it's the on your own risk way ... e.g. adding a PPA such as you did ... Yep, you have already chosen the "on your own risk way" ... Read this (emphasis is mine):

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:ubuntu... to your system's Software Sources.

... that text is quoted from the Launchpad link you included in your question and it's not limited to that specific PPA (which might be of good reputation), but it is what it is.

That PPA enables for installing the package gcc-13 on Ubuntu 22.04 by essentially including that package with its dependencies that can not be satisfied from the Ubuntu 22.04 official repositories and of course some other work might be involved like modifying post-install and/or pre-install scripts and ensuring none of the added package or its dependencies will conflict with existing essential system packages and so forth.

In the case of gcc-13 and gcc-13-aarch64-linux-gnu, which are also made available in Ubuntu 23.04/23.10 official repositories, one might ponder the possibility of installing them from 23.04/23.10 repositories on an Ubuntu 22.04 system? ... Well, yeah surely possible (for these two) and it should make the "on your own risk" zone a bit more appealing as those repositories are official and trusted, but the unsupported part will still apply.

Anyway, I have quickly traced those two packages and their dependencies and then installed both from the official repositories of Ubuntu 23.10 on an Ubuntu 22.04 system successfully without any noticeable drawbacks AFAIK ... After all the GNU C compiler is not essential to the functionality of Ubuntu and is offered as an optional package for manual install.

However, there is probably most likely certainly an extremely big problem awaiting if you're not careful enough i.e. you must make sure no other packages from that repository get installed by any means including automatic-updates so turn all those off and fully update your system first, then follow all instructions precisely (still on your own risk of course) ... If other packages got installed, they might break your system so dangerously badly and possible beyond any applicable repair and of course this is as unsupported as your PPA installed packages ... So, we will not provide any support for either.

Needless to say that I don't prefer it or like it this way, but you seem to need it so I wrote it.

The idea is, basically, to add the official Ubuntu repository containing those two packages, refresh the local cached sources list, install those two packages and promptly delete the added repository from you system like so:

First, add the repository:

echo "deb http://cz.archive.ubuntu.com/ubuntu mantic main" |
sudo tee /etc/apt/sources.list.d/temporary-repository.list

Second, update package lists:

sudo apt update

Third, only install gcc-13 and gcc-13-aarch64-linux-gnu:

sudo apt install gcc-13 gcc-13-aarch64-linux-gnu

Fourth, delete that temporary repository:

sudo rm /etc/apt/sources.list.d/temporary-repository.list

Finally, update your cached packages lists:

sudo apt update

Notice

  • You might need to first remove the gcc-13 package you have already installed from that PPA and the PPA itself to avoid possible dependency version mismatch.

  • You'll need to run those by version number i.e. gcc-13 -v and aarch64-linux-gnu-gcc-13 -v and not just gcc or you can use the Ubuntu alternatives system to choose the default version.

๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ sysadmin โ€บ how to install gcc compiler on ubuntu
How to Install GCC Compiler on Ubuntu {3 Simple Methods}
February 20, 2025 - sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y ยท 3. Use the wget command to download the GCC source code from the GCC website. In this example, the file gcc-13.2.0.tar.gz contains the source code for GCC version 13.2.0:
People also ask

Does GCC come pre-installed on Ubuntu?
No. Ubuntu desktop and server images do not include GCC by default. You need to install the build-essential package, which provides GCC, G++, make, and essential development headers.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
Why does "unable to locate package gcc-14" appear on Ubuntu?
This error occurs when the Universe repository is not enabled. GCC versions beyond the default are in the Universe component. Run sudo add-apt-repository universe and sudo apt update, then retry the installation.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
How do I fix "gcc: command not found" on Ubuntu?
Ubuntu does not include GCC by default. Install it with sudo apt install build-essential, which provides gcc, g++, and make. If you installed a specific version like gcc-14, either use the versioned binary (gcc-14) directly or register it with update-alternatives to create the unversioned gcc symlink.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 76168157 โ€บ installing-gcc-13-on-ubuntu-22-04
c++ - Installing GCC-13 on Ubuntu 22.04 - Stack Overflow
I have had success building my own gcc-13 on Ubuntu Jammy 22.04.2. Check out my GitHub script. github.com/slyfox1186/script-repo/blob/main/shell/installers/โ€ฆ
๐ŸŒ
DEV Community
dev.to โ€บ nullity โ€บ zai-ubuntu-2004-an-zhuang-gcc-13-1kd1
Install or uninstall gcc 13 on Ubuntu 20.04 - DEV Community
March 22, 2024 - sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install gcc-13 g++-13
๐ŸŒ
Ubuntu
launchpad.net โ€บ ubuntu โ€บ +source โ€บ gcc-13
gcc-13 package : Ubuntu
+6-13-dbg: GNU Standard C++ Library v3 (debug build) lib64gcc-13-dev: GCC support library (64bit development files) lib64gfortran- 13-dev: Runtime library for GNU Fortran applications (64bit development files) lib64go-13-dev: Runtime library for GNU Go applications (64bit development files) lib64go22: Runtime library for GNU Go applications (64bit) lib64gphobos-
๐ŸŒ
Developernote
developernote.com โ€บ 2023 โ€บ 08 โ€บ installing-gcc13-on-ubuntu-22-04
Installing GCC13 on Ubuntu 22.04 | DeveloperNote.com
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install gcc-13 g++-13 ll /usr/bin/gcc-13 ll /usr/bin/g++-13 update-alternatives --display gcc ll /etc/alternatives/g* sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++ sudo ...
๐ŸŒ
LinuxCapable
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
December 6, 2023 - You can install GCC compiler on Ubuntu 26.04, 24.04, and 22.04 LTS through the default repositories, the Ubuntu Toolchain PPA, or source compilation. Ubuntu 26.04 ships GCC 15 as its default compiler with versions 11 through 16 available, Ubuntu ...
Find elsewhere
Top answer
1 of 4
50

gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:

  • Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
  • Step 2: make another build dir

Note this is important as running ./configure from within the source directory is not supported as documented here.

$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 3: installing GCC prequisites and run configure again

The missing libraries will be shown in above ./confgiure output, search and install them one by one.

$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++

An alternative is to run the download_prerequisites script.

 cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 4: compile gcc-12
$ make -j16

Still flex is missing:

$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install

Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:

$ sudo apt install gcc-12
2 of 4
16

You can use Homebrew to install pre-built binaries. Follow instructions to install Homebrew at https://brew.sh/, then

brew install gcc for default GCC (currently 11) or brew install gcc@12 for gcc-12.

Note that it may compile missing dependencies.

๐ŸŒ
DedicatedCore
dedicatedcore.com โ€บ home โ€บ how to install gcc compiler on ubuntu 22.04
How to Install GCC Compiler on Ubuntu 22.04 - DedicatedCore Blog
January 24, 2025 - ... In this case, the GCC version ... (Personal Package Archives). ... Use the command listed below to install one or more GCC versions. For instance, type: to install GCC 12 and GCC 13......
๐ŸŒ
Electroorg
electroorg.com โ€บ blogs โ€บ 15573749
How to install gcc 13 on Ubuntu - blog post
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update ... You may want to set GCC 13 as the default compiler. You can do this by updating the update-alternatives system. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 sudo update-alternatives --install ...
๐ŸŒ
Nilo Menezes
blog.nilo.pro.br โ€บ en โ€บ posts โ€บ 2024-04-18-compilando-o-gcc-13-2-0-no-ubuntu-22-04-lts
Compiling the GCC 13.2.0 on Ubuntu 22.04 LTS :: Nilo Menezes
$ gcc-13 --version gcc-13 (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions.
๐ŸŒ
Snapcraft
snapcraft.io โ€บ gcc-13
Install gcc-13 on Linux | Snap Store
May 26, 2025 - View in Desktop store ยท Make sure snap support is enabled in your Desktop store. Install using the command line ยท sudo snap install gcc-13 ยท Don't have snapd? Get set up for snaps.
๐ŸŒ
Ubuntu
documentation.ubuntu.com โ€บ ubuntu-for-developers โ€บ reference โ€บ availability โ€บ gcc
Available GCC versions - Ubuntu for Developers
5 days ago - Ubuntu GCC (deb) packages:,,, Ubuntu version, available GCC versions, gcc-defaults version,,, 25.10 (Questing Quokka), 11, 12, 13, 14, 15, 15,, 25.04 (Plucky Puffin), 11, 12, 13, 14, 15, 14,, 24.10...
๐ŸŒ
Lindevs
lindevs.com โ€บ install-gcc-on-ubuntu
Install gcc 13 on Ubuntu 22.04 | Lindevs
October 29, 2023 - This tutorial demonstrates how to install gcc 13 on Ubuntu 22.04.
๐ŸŒ
Markusthill
markusthill.github.io โ€บ blog โ€บ 2024 โ€บ installing-gcc
Short Notes: Installing GCC 13 on Debian and Ubuntu | Markus Thill
sudo update-alternatives --install ... /usr/bin/g++-13 13 ยท Follow the on-screen instructions to select GCC 13 as the default compiler: sudo update-alternatives --config gcc sudo update-alternatives --config g++ Check the currently configured version, for example, with: gcc ...
๐ŸŒ
Snapcraft
snapcraft.io โ€บ install โ€บ gcc-13 โ€บ ubuntu
Install gcc-13 on Ubuntu using the Snap Store | Snapcraft
May 26, 2025 - Get the latest version of gcc-13 for on Ubuntu - the GNU Compiler Collection version 13.
Top answer
1 of 5
240

The best way to correctly install gcc-4.9 and set it as your default gcc version use:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

The --slave, with g++, will cause g++ to be switched along with gcc, to the same version. But, at this point gcc-4.9 will be your only version configured in update-alternatives, so add 4.8 to update-alternatives, so there actually is an alternative, by using:

sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

Then you can check which one that is set, and change back and forth using:

sudo update-alternatives --config gcc

If you have an issue with update-alternatives gcc priority 60 not being higher than previous versions installed you can use the previous update-alternatives --config gcc command to check installed versions and use:

sudo update-alternatives --remove gcc

Or:

sudo update-alternatives --remove-all gcc

NOTE: You could skip installing the PPA Repository and just use /usr/bin/gcc-4.9-base but I prefer using the fresh updated toolchains.


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.

2 of 5
63

Ultimate mega master compatibility table

OK let's do this:

                  GCC                              clang
        +-------------------------------------+-------------------------------------------------+
        | 15 14 13 12 11 10  9  8  7  6  5  4 | 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5 |
+-------+-------------------------------------+-------------------------------------------------+
| 25.10 |  D  M  M  M  M                      |  D  M  M  M                                     |
| 25.04 |     D  M  M  M                      |  D  M  M  M                                     |
| 24.10 |     D  M  M  M                      |     D  M  M  M  M  M                            |
| 24.04 |     M  D  M  M  M  M                |        D  M  M  M  M                            |
| 23.10 |        D  M  M  M  M                |           M  D  M  M  M                         |
| 23.10 |        D  M  M  M  M                |              D  M  M  M                         |
| 23.04 |        M  D  M  M  M                |              M  D  M  M                         |
| 22.10 |           D  M  M  M                |                 D  M  M                         |
| 22.04 |        P  M  D  M  M                |                    D  M  M  M                   |
| 21.10 |              D  M  M  M             |                       D  M  M  M  M             |
| 21.04 |              M  D  M  M  M          |                          D  M  M  M             |
| 20.10 |                 D  M  M  M          |                             D  M  M  M  M  M    |
| 20.04 |                 P  D  M  M          |                                D  M  M  M  M    |
| 19.10 |                    D  M  M          |                                                 |
| 19.04 |                    M  D  M  M       |                                                 |
| 18.10 |                       D  M  M  M    |                                                 |
| 18.04 |                 P  P  M  D  M  M    |                                   M  M  M  D  M |
| 16.04 |                    P  P  P  P  D  M |                                                 |
+-------+-------------------------------------+-------------------------------------------------+
  • D: Default GCC

    sudo apt-get update
    sudo apt-get install gcc g++
    gcc --version
    

    Whatever the gcc package aliases to: https://packages.ubuntu.com/search?keywords=gcc and also present in manifests: How do I list the default installed packages?

  • M: Present in Main repo

    sudo apt-get update
    sudo apt-get install gcc-X g++-X
    gcc-X --version
    

    All Ubuntu versions that have a hit for a given GCC version, e.g. for GCC 7: https://packages.ubuntu.com/search?keywords=gcc-7 or clang 7 https://packages.ubuntu.com/search?keywords=clang-7

    The minor versions of these packages can get updated from time to time within a single Ubuntu version (on the . revisions?), e.g. 8.3.0 to 8.4.0 so we are not keeping track of that.

  • P: ppa:ubuntu-toolchain-r/test, which is owned by Ubuntu people and therefore can be trusted to not be a virus, although it is possibly unstable:

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

    Full list: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test

    The minor versions of these packages can get updated from time to time, e.g. 8.3.0 to 8.4.0.

Blank spaces on the table mean either "no package available" or "I didn't bother to check". Notably I've not been looking into PPA packages too thoroughly. Edits accepted.

All the questions:

  • install gcc-9 on Ubuntu 18.04?
  • How to install gcc-7 or clang 4.0?
  • install gcc-9 on Ubuntu 18.04?
  • What are the GCC and clang versions available in Ubuntu 18.04?

How to set a non-default GCC as the default?

E.g., you installed /usr/bin/gcc-7 but you want to use that instead of /usr/bin/gcc when you run gcc main.c.

Use sudo update-alternatives as mentioned in other answers: https://askubuntu.com/a/581497/52975 It creates the required symlinks for you.

See also: What exactly does `update-alternatives` do?

How to build your own toolchain from source

If even the PPA is not old/new enough for you, see this:

  • https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/52454603#52454603
  • https://stackoverflow.com/questions/26305738/can-i-build-gcc-for-arm-with-an-x64-one/26306591#26306591

Older GCC version questions

  • Ubuntu 20.04 - gcc version lower than gcc-7
  • How to use an older version of GCC
๐ŸŒ
GNU
gcc.gnu.org โ€บ install
Installing GCC - GNU Project
This document describes the generic installation procedure for GCC as well as detailing some target specific installation instructions.
๐ŸŒ
Linux Mint Forums
forums.linuxmint.com โ€บ board index โ€บ main edition support โ€บ software & applications
How do I update gcc to 13.2.0? - Linux Mint Forums
If you need gcc-13 now you'll have some hoops to jump through. Compile it from source or use this PPA: https://launchpad.net/~ubuntu-toolchain ... buntu/test. It could break things. After installing gcc-13 package from there you can invoke it with command gcc-13.