I wanted to install gcc-6 alongside my existing installation of gcc-9 and this is how I did it. First off, sudo apt install gcc-6 didn't work because the package wasn't found so I had to add a new repository that contained gcc-6. To do this, I first found a repository that contains gcc-6 from Google and ended up at: https://packages.ubuntu.com/bionic/gcc-6

From there, I chose an architecture (amd64) which took me to a page with all the mirrors. I added the first mirror (mirrors.kernel.org/ubuntu) to /etc/apt/sources.list and did sudo apt update and then installed gcc-6 with sudo apt install gcc-6.

To switch between gcc versions, I used the following:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9

sudo update-alternatives --config g++
Answer from Michael Kiros on Stack Overflow
🌐
GitHub
gist.github.com › application2000 › 73fd6f4bf1be6600a2cf9f56315a2d91
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04) · GitHub
sudo apt-get update -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 ...
🌐
Vegastack
vegastack.com › tutorials › how-to-install-gcc-compiler-on-ubuntu-18-04
How to Install GCC Compiler on Ubuntu 18.04
August 14, 2024 - In this tutorial, we will show you how to install GCC on Ubuntu 18.04.
🌐
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.
🌐
LinuxHostSupport
linuxhostsupport.com › home › how to install gcc on ubuntu 18.04
How to Install GCC on Ubuntu 18.04 | LinuxHostSupport
November 30, 2019 - In this article, we will show you how to install GCC on an Ubuntu 18.04 server. If we use the apt command to install GCC from a repository, we will have
Find elsewhere
🌐
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++ ...
🌐
Tutorials24x7
tutorials24x7.com › c › how-to-install-gcc-on-ubuntu-1804-lts
Install GCC for C++ on Ubuntu 18.04 LTS | Tutorials24x7
September 13, 2019 - The above-mentioned commands installed GCC 7.5 on Ubuntu 18.04 LTS while writing this tutorial. This is how we can install and verify the GCC on Ubuntu. In the previous step, we have installed the default GCC i.e. GCC 7.5.0 which is not the latest one. In this section, we will install the latest GCC using the PPP. The most recent version of GCC available while writing this tutorial is 10...
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc compiler on ubuntu 18.04
How to Install GCC Compiler on Ubuntu 18.04 | Linuxize
October 31, 2019 - This tutorial covers the steps required to install the GCC compiler on Ubuntu 18.04.
🌐
LinuxConfig
linuxconfig.org › home › how to install gcc the c compiler on ubuntu 18.04 bionic beaver linux
How to install GCC the C compiler on Ubuntu 18.04 Bionic Beaver Linux
September 22, 2025 - Another way to install gcc compiler is to install it as part of build-essential package. build-essential package will also install additional libraries as well as g++ compiler. In most cases or if unsure this is exactly what you need: ... $ gcc --version gcc (Ubuntu 7.2.0-18ubuntu2) 7.2.0 Copyright ...
🌐
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
April 30, 2026 - 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:
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.

Copy$ which gcc | xargs file

The output will be

Copy/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.
Copy# 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.
Copyalias 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.
Copy# 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.

🌐
Ask Ubuntu
askubuntu.com › questions › 1142289 › ubuntu-18-10-how-to-install-a-specific-version-of-gcc
apt - Ubuntu 18.10 - how to install a specific version of gcc - Ask Ubuntu
May 11, 2019 - I located gcc 8.2.0 here as part of the core for Cosmic (18.10) and downloaded it. apt still complained when I tried to install it, saying it needed to install 8.3. ... sudo apt policy gcc gcc-8 apt policy gcc gcc-8 gcc: Installed: 4:8.3.0-1ubuntu1.1 Candidate: 4:8.3.0-1ubuntu1.1 Version table: *** 4:8.3.0-1ubuntu1.1 500 500 http://us.archive.ubuntu.com/ubuntu cosmic-updates/main amd64 Packages 100 /var/lib/dpkg/status 4:8.2.0-1ubuntu1 500 500 http://mirrors.kernel.org/ubuntu cosmic/main amd64 Packages 500 http://us.archive.ubuntu.com/ubuntu cosmic/main amd64 Packages gcc-8: Installed: 8.3.0-6
🌐
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
packages.ubuntu.com › gcc
Ubuntu – Package Search Results -- gcc
October 20, 2022 - noble (24.04LTS) (devel): GNU C compiler (cross compiler for armel 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
🌐
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 ...