You need to update your system:

sudo apt update
sudo apt upgrade
sudo apt install gcc
Answer from GAD3R on Stack Exchange
🌐
LinuxTect
linuxtect.com › how-to-install-gcc-compiler-on-ubuntu
How To Install GCC Compiler On Ubuntu? – LinuxTect
We can install the GCC with the following apt command for Ubuntu, Debian, Mint etc. We also provide the sudo command for root privileges.
People also ask

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
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
Top answer
1 of 5
20

I'm still on Ubuntu 22.04 LTS but needed g++14. The sudo apt-get gcc-14 did not work for me, as it installed clang++14 for some reason (perhaps a misconfiguration on my part). What did work for me was following the instructions I found at https://www.dedicatedcore.com/blog/install-gcc-compiler-ubuntu/

The steps I took:

sudo apt install build-essential
sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xf gcc-14.1.0.tar.gz
cd gcc-14.1.0
./configure -v --build=$(uname -m)-linux-gnu --host=$(uname -m)-linux-gnu --target=$(uname -m)-linux-gnu --prefix=/usr/local/gcc-14.1.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-14.1.0
make
sudo make install

And if you would like to make it the default:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.1.0/bin/g++-14.1.0 14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.1.0/bin/gcc-14.1.0 14

After that, g++ showed I was running version 14.1.0. I was then able to compile my project that included some c++20/23 features that were not in the previous versions of g++ (chrono/format).

2 of 5
15

GCC-14 (and G++-14) is available in the Universe repository for Ubuntu 24.04, as evident in the Ubuntu Package archive.

It is equally evident that this package is not available for Ubuntu 22.04, so installing this on 22.04 will require some third-party interference, or you have to compile it yourself.

See here on how to enable the Universe repositories.

🌐
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 - 2. Install the libgmp3-dev, libmpfr-dev, and libmpc-dev packages to facilitate compiling GCC from source: sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
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.

Find elsewhere
🌐
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 - To upgrade to a newer GCC major version from the repositories, install the target version and update your default: sudo apt install gcc-14 g++-14 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 \ --slave /usr/bin/g++ ...
🌐
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 - Perform the steps below to install the GCC Compiler Ubuntu 18.04: Start by updating the packages list: Terminal · sudo apt update · Install the build-essential package by typing: Terminal · sudo apt install build-essential · The command ...
🌐
CyberPanel
cyberpanel.net › blog › install-gcc-on-ubuntu
How To Install GCC On Ubuntu: Easiest Methods Explained!
March 18, 2025 - 2. Next, install the libgmp3-dev, libmpfr-dev, and libmpc-dev packages to help compile GCC from source: sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
🌐
LinuxConfig
linuxconfig.org › home › how to install gcc the c compiler on ubuntu 22.04 lts jammy jellyfish linux
How to install GCC the C compiler on Ubuntu 22.04 LTS Jammy Jellyfish Linux
January 8, 2024 - Installation of GCC can be achieved by using the apt install command as you will see below. ... Although you can install the C compiler separately by installation of the gcc package, the recommended way to install the C compiler on Ubuntu 22.04 ...
Top answer
1 of 3
7

To install gcc-7 on ubuntu you should use this ppa:

sudo add-apt-repository ppa:jonathonf/gcc
sudo apt-get update

Then run: apt-cache search gcc-7

sample output :

gcc-7-base - GCC, the GNU Compiler Collection (base package)
gcc-7 - GNU C compiler
gcc-7-multilib - GNU C compiler (multilib support)
gcc-7-plugin-dev - Files for GNU GCC plugin development.
gcc-7-test-results - Test results for the GCC test suite
lib32gcc-7-dev - GCC support library (32 bit development files)
libgcc-7-dev - GCC support library (development files)
gcc-7-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-7-hppa64-linux-gnu - GNU C compiler (cross compiler for hppa64)
gcc-7-locales - GCC, the GNU compiler collection (native language support files)
gcc-7-source - Source of the GNU Compiler Collection
libx32gcc-7-dev - GCC support library (x32 development files)
gcc-7-offload-nvptx - GCC offloading compiler to NVPTX
lib64gcc-7-dev - GCC support library (64bit development files)

Install gcc-7:

sudo apt install gcc-7
2 of 3
2

If you need to setup a test rig with the compiler, then Fedora 26 ships with GCC 7.1.

You can also find GCC 7 in Debian 10/Buster (Debian 9 with Testing repo enabled). For Debian, you must apt-get install gcc-7 g++-7.

For completeness, its not clear which version of the Microsoft compilers support C++17 and std::byte (the reason I needed the compiler for testing).

And thanks to GAD3R for his help. The reason I avoided it was I could not establish provenance for some of the PPAs.

🌐
Namehero
namehero.com › blog › how-to-install-gcc-on-ubuntu
How To Install GCC On Ubuntu
November 4, 2024 - Enter the following command and press Enter: sudo apt update · Step 3: Install GCC · Now, it’s time to install GCC. Enter the following command and press Enter: sudo apt install gcc ·
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to install gcc on ubuntu 22.04 [and compile a c program]
How to Install GCC on Ubuntu 22.04 [and Compile a C Program] | Cherry Servers
November 7, 2025 - To update the package list, use the following command: sudo apt update · We now install GCC with the following command. sudo apt install gcc · If GCC is already installed on your system, the command will list the version installed.
🌐
Learn Ubuntu
learnubuntu.com › install-gcc
How to Install GCC on Ubuntu
December 5, 2022 - I assume you want to install GCC because you are working on a software project written in the C programming language. In that case, I advise you to install the build-essential pacakge. It is a meta package of sorts. A meta package is a package that does not have anything of its own but rather acts as a package to install a collection of related packages. The build-essential meta package can be easily installed with the apt 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 - The default Ubuntu repositories ... command as root or user with sudo privileges : Terminal · sudo apt update sudo apt install build-essential ·...
🌐
Baeldung
baeldung.com › home › installation › how to install the latest version of gcc on ubuntu
How to Install the Latest Version of GCC on Ubuntu | Baeldung on Linux
November 17, 2024 - In this case, we use the ubuntu-toolchain-r/test PPA. So, let’s leverage the add-apt-repository command to add this PPA to the system: $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test ... Now, let’s go ahead to the final step.
🌐
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 - ... Users can handle several GCC versions with the update-alternatives tool: The update-alternatives filesystem should now include the GCC 12 alternative. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 --slave /usr/bin/g++ ...
🌐
iO Flood
ioflood.com › blog › install-gcc-command-linux
Installing and Using the GCC Command: Linux User Guide
January 2, 2024 - On Debian-based distributions, you can install a specific GCC version with the apt package manager: sudo apt install gcc-8 # Output: # 'Reading package lists... Done' # 'Building dependency tree' # 'Reading state information...