gcc-10 is now available in the Ubuntu tool chains.

Add the PPA and install gcc-10:

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

For g++-10:

   sudo apt install g++-10

At the end you need to update the alternatives for compilers (reference):

#Remove the previous alternatives
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++

#Define the compiler
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 30

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

#Confirm and update (You can use the default setting)
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Answer from P.P on askubuntu.com
🌐
GitHub
gist.github.com › application2000 › 73fd6f4bf1be6600a2cf9f56315a2d91
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04) · GitHub
As a side note, the daily build of the next Ubuntu 20.10 does install 10.1.0. Today's screenshot of repo https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test/+packages: ... sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get install build-essential software-properties-common -y && sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && sudo apt-get update -y && sudo apt-get install gcc-10 g++-10 -y && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10 && sudo update-alternatives --config gcc
🌐
Ubuntu
packages.ubuntu.com › focal › gcc-10
Details of package gcc-10 in focal
two or more packages specified (gcc-10 focal) Content Copyright © 2025 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
Ahelpme
ahelpme.com › home › linux › ubuntu › install and make gnu gcc 10 default in ubuntu 20.04 focal
Install and make GNU GCC 10 default in Ubuntu 20.04 Focal | Any IT here? Help Me!
October 18, 2021 - Use sudo before each command, if installation is performed by a user other than root: sudo apt update -y sudo apt upgrade -y sudo apt install -y build-essential sudo apt install -y gcc-10 g++-10 cpp-10 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ ...
🌐
LinuxCapable
linuxcapable.com › home › ubuntu › how to install gcc on ubuntu 26.04, 24.04 and 22.04
How to Install GCC on Ubuntu 26.04, 24.04 and 22.04 - LinuxCapable
1 week ago - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 120 \ --slave /usr/bin/g++ g++ /usr/bin/g++-12 \ --slave /usr/bin/gcov gcov /usr/bin/gcov-12 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 \ --slave /usr/bin/g++ g++ /usr/bin/g++-11 \ --slave /usr/bin/gcov gcov /usr/bin/gcov-11 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 \ --slave /usr/bin/g++ g++ /usr/bin/g++-10 \ --slave /usr/bin/gcov gcov /usr/bin/gcov-10 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 \ --slave /usr/bin/g++ g++ /usr/bin/g++-9 \ --slave /usr/bin/gcov gcov /usr/bin/gcov-9 · If you installed GCC 15 from the Toolchain Test PPA on Ubuntu 24.04 or 22.04, register it with the same pattern:
🌐
Solarian Programmer
solarianprogrammer.com › 2016 › 10 › 07 › building-gcc-ubuntu-linux
Building GCC 10 on Ubuntu Linux | Solarian Programmer
October 7, 2016 - 1 cd ~ 2 mkdir build && cd build 3 ../gcc-10.1.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-10.1.0 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-10.1 · Now, we are ready to ...
Find elsewhere
🌐
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 - This guide shows how to install GCC on Ubuntu and start compiling code on your system in no time.
Top answer
1 of 1
18

This is a common pattern in linux. When there are multiple versions of the same program installed, though the executables are all present in the /usr/bin/ directory, only one of them is "visible" as that program. For example, if you install gcc-9 and gcc-10, both executables are present as /usr/bin/gcc-9 and /usr/bin/gcc-10 but only one of them is visible as gcc. This happens by symlinking a preferred version to the same directory as /usr/bin/gcc. In ubuntu 20.04, the preferred version is gcc-9 and so, gcc-9 is symlinked as gcc.

You can check this by running the following command.

$ which gcc | xargs file

The output will be

/usr/bin/gcc: symbolic link to gcc-9

There are a few things you can do to use gcc-10 as your c compiler.

  1. Directly call the gcc-10 executable. Instead of using gcc <code.c>, call gcc-10 <code.c>.
  2. You can manually symlink gcc-10 as the preferred gcc. Assuming you did not modify the system paths, the following command can be used.
# ln -s /usr/bin/gcc-10 /usr/local/bin/gcc

This works because, by default, the executables in /usr/local/bin/ take precedence over /usr/bin/.

  1. If you are using bash, you can create an alias for gcc as gcc-10. Add the following line to your .bashrc.
alias gcc="gcc-10"

Remember to relaunch bash or source ~/.bashrc.

  1. Using update-alternatives (Thanks to @ted-lyngmo for pointing it out). Debian based distributions supply a separate program, that can make symlinking easier / more functional. Read more using man update-alternatives. To use gcc-10 as the preferred gcc, use the following command.
# update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60

The above command says, /usr/bin/gcc is the link needed and the name is gcc, the target executable is /usr/bin/gcc-10 and it has a priority of 60.

This links gcc to /etc/alternatives/gcc, which itself is a symlink to /usr/bin/gcc-10. If a higher priority program is added to update-alternatives, /etc/alternatives/gcc points to the higher priority program.

If you don't have any specific reason, I would also recommend to upgrade to a newer ubuntu version, so that the default gcc is a newer one.

I read on the gcc website that version 9.4 is more up-to-date than some 10.x versions.

With newer gcc versions, new features are added. Support for newer c/c++ standards are also added. Eg. You can read the changes for gcc-10 here. But people still need gcc-9 because some programs only build with gcc-9. So, GNU maintains gcc-9 (and much older versions) for a long time. Bugs are fixed, and newer releases are made. This can happen after the release of a newer gcc version. So, it is very much possible that a version of gcc-9 is newer than a version of gcc-10.

🌐
AddictiveTips
addictivetips.com › home › how to install gcc on ubuntu
How to install GCC on Ubuntu
March 22, 2021 - You can also install GCC 10 by installing the gcc-10 and g++-10 packages. ... If you need to get GCC working on Ubuntu but don’t want to use the terminal, you can do it with the Synaptic Package Manager.
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc (build-essential) on ubuntu 20.04
How to Install GCC (build-essential) on Ubuntu 20.04 | Linuxize
June 4, 2020 - Install the desired GCC and G++ versions by typing: ... The commands below configures alternative for each version and associate a priority with it. The default version is the one with the highest priority, in our case that is gcc-10.
🌐
Quora
quora.com › How-do-you-install-GCC-10-2-with-sudo-apt-get-install-gcc-x-g-x-GCC-G-Linux
How to install GCC 10.2 with 'sudo apt get install gcc x g++ x' (GCC, G++, Linux) - Quora
It is best to keep the version that came with the distro release. If you want GCC 10.2, you should configure and build it from source in /usr/local or create a container and build it in the container.
🌐
Ubuntu
launchpad.net › ubuntu › focal › i386 › gcc-10-base › 10.3.0-1ubuntu1~20.04
10.3.0-1ubuntu1~20.04 : gcc-10-base : i386 : Focal (20.04) : Ubuntu
i386 build of gcc-10 10.3.0-1ubuntu1~20.04 in ubuntu focal RELEASE produced these files: gcc-10-base_10.3.0-1ubuntu1~20.04_i386.deb (19.7 KiB) Breaks: gnat (<< 7) • Take the tour • Read the guide · © 2004 Canonical Ltd.
🌐
LinuxConfig
linuxconfig.org › home › how to switch between multiple gcc and g++ compiler versions on ubuntu 22.04 lts jammy jellyfish
Install GCC G++ on Ubuntu 22.04 Easily
February 28, 2022 - $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 $ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10 · Check the available C and C++ compilers list on your Ubuntu 22.04 system and select desired version by entering relevant selection number:
🌐
Vegastack
vegastack.com › tutorials › how-to-install-gcc-compiler-on-ubuntu-20-04
How to Install GCC Compiler on Ubuntu 20.04
August 14, 2024 - sudo apt install software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test · 3) Next, install the necessary GCC and G++ versions by: sudo apt install gcc-8 g++-8 gcc-9 g++-9 gcc-10 g++-10
🌐
GNU
gcc.gnu.org › install
Installing GCC - GNU Project
The latest version of this document is always available at https://gcc.gnu.org/install/. It refers to the current development sources, instructions for specific released versions are included with the sources.
🌐
Ubuntu
packages.ubuntu.com › focal › gcc-10-base
Details of package gcc-10-base in focal
two or more packages specified (gcc-10-base focal) Content Copyright © 2025 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
Ubuntu
packages.ubuntu.com › focal › amd64 › gcc-10-base › download
gcc-10-base_10.5.0-1ubuntu1~20.04_amd64.deb
two or more packages specified (gcc-10-base focal) Content Copyright © 2025 Canonical Ltd.; See license terms. Ubuntu is a trademark of Canonical Ltd. Learn more about this site.
🌐
Ubuntu
packages.ubuntu.com › gcc
Ubuntu – Package Search Results -- gcc
October 20, 2022 - noble (24.04LTS) (devel): GNU C compiler (cross compiler for armhf architecture) [universe] 10.5.0-4ubuntu2cross1: amd64 arm64 i386 ppc64el · jammy (22.04LTS) (devel): GCC, the GNU Compiler Collection (base package) [universe] 10.5.0-1ubuntu1~22.04cross1 [security]: amd64 i386 10.3.0-8ubuntu1cross1 [ports]: arm64 ppc64el