How to Install GCC on Linux
GCC is the GNU Compiler Collection: the standard C and C++ compiler on Linux. You need it to compile C/C++ programs, to build software from source, and for language packages that compile native extensions (Python wheels, npm modules, Ruby gems).
In practice you rarely want only gcc. You want the basic toolchain: the C and C++ compilers, make and the C library headers. Every distribution has a single package or group for that.
Check first whether it is already there:
gcc --version
g++ --version
Ubuntu and Debian
sudo apt update
sudo apt install build-essential
gcc --version
build-essential pulls in gcc, g++, make, libc6-dev and dpkg-dev. Add gdb for debugging and manpages-dev for the C library man pages if you want them.
The default compiler follows the release: GCC 13 on Ubuntu 24.04, GCC 14 on Debian 13, GCC 15 on Ubuntu 26.04.
Fedora, RHEL, Rocky, AlmaLinux, Amazon Linux 2023
For just the compilers and make:
sudo dnf install gcc gcc-c++ make
For the full development toolchain (also autoconf, automake, git, rpm-build and more):
sudo dnf group install "Development Tools" # RHEL, Rocky, Alma, AL2023 (dnf 4)
sudo dnf group install development-tools # Fedora 41+ (dnf5 wants the group ID)
dnf group list shows the group names and IDs available on your system.
Arch and openSUSE
sudo pacman -S --needed base-devel # Arch
sudo zypper install gcc gcc-c++ make # openSUSE
Test the compiler
cat > hello.c <<'EOF'
#include <stdio.h>
int main(void) {
printf("Hello from GCC\n");
return 0;
}
EOF
gcc -Wall -O2 -o hello hello.c
./hello
For C++, save the code as hello.cpp with #include <iostream> and compile with g++ instead. Use g++ (not gcc) to link C++ programs, so the C++ standard library gets linked in.
Install a different GCC version
Ubuntu and Debian
Several GCC versions are packaged side by side as gcc-N:
apt-cache search --names-only '^gcc-[0-9]+$'
sudo apt install gcc-14 g++-14
gcc-14 --version
The simplest and safest way to use a specific version is to name it per build. Nothing else on the system changes:
make CC=gcc-14 CXX=g++-14
CC=gcc-14 CXX=g++-14 cmake -B build
If you really want gcc itself to point to another version, register the versions with update-alternatives:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 --slave /usr/bin/g++ g++ /usr/bin/g++-13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 --slave /usr/bin/g++ g++ /usr/bin/g++-14
sudo update-alternatives --config gcc
The --slave part keeps g++ in step with gcc, so you never compile with one version and link with another. Be aware that an upgrade of the gcc package can reset /usr/bin/gcc, and that kernel modules (DKMS) should be built with the same compiler the kernel was built with.
RHEL, Rocky and AlmaLinux
Newer compilers come as GCC Toolset packages. They install under /opt/rh and do not replace the system compiler:
dnf list available 'gcc-toolset-*-gcc'
sudo dnf install gcc-toolset-14
scl enable gcc-toolset-14 bash # new shell with GCC 14 first in PATH
gcc --version
In scripts and CI, source /opt/rh/gcc-toolset-14/enable does the same without starting a new shell.
Building GCC from source
Possible, but slow (often an hour or more) and rarely needed now that distributions ship several versions. If you do it, install into its own prefix such as /opt/gcc-15 and call it by full path, so it never shadows the system compiler.
Troubleshooting
gcc: command not found: the toolchain is not installed. Usebuild-essentialor the dnf commands above.fatal error: stdio.h: No such file or directory: the C library headers are missing. Installlibc6-dev(Debian/Ubuntu) orglibc-devel(Fedora/RHEL);build-essentialincludes it.fatal error: openssl/ssl.h: No such file or directory: a library's development headers are missing. Install the-devor-develpackage, herelibssl-devoropenssl-devel.apt-file search openssl/ssl.hordnf provides '*/openssl/ssl.h'finds the right package for any header.g++: command not foundorcc1plus: not found: only the C compiler is installed. Addg++(Debian/Ubuntu) orgcc-c++(Fedora/RHEL).
Quick reference
sudo apt install build-essential # Ubuntu, Debian
sudo dnf install gcc gcc-c++ make # Fedora, RHEL, AL2023
sudo dnf group install "Development Tools" # RHEL family, full toolchain
sudo dnf group install development-tools # Fedora 41+
sudo pacman -S --needed base-devel # Arch
sudo apt install gcc-14 g++-14 # extra version on Ubuntu/Debian
make CC=gcc-14 CXX=g++-14 # use it for one build
sudo dnf install gcc-toolset-14 && scl enable gcc-toolset-14 bash # newer GCC on RHEL
