GCC (GNU Compiler Collection) provides C and C++ compilers used for building software from source, compiling AUR packages, and developing applications on Linux. Arch Linux ships GCC in its core repository and keeps it on the latest stable release through rolling updates. By the end, you will have a working compiler verified through test programs, with the option to extend GCC with frontends for Fortran, Go, D, and other languages.
Update Arch Linux
Synchronize the package database and upgrade all installed packages before installing new software. This prevents dependency conflicts and ensures you get the latest available version of GCC.
sudo pacman -Syu
This guide uses
sudofor commands that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add and manage sudo users on Arch Linux.
Install GCC on Arch Linux
Arch Linux offers two approaches for installing GCC. The standalone gcc package provides only the C and C++ compilers, while the base-devel metapackage bundles GCC with build tools required for compiling packages from source.
| Method | What It Installs | Best For |
|---|---|---|
gcc package | C and C++ compilers, gcc-libs, binutils | Minimal setup, compiling C/C++ code only |
base-devel metapackage | GCC plus autoconf, automake, make, patch, pkgconf, and 20+ build tools | Building AUR packages, source builds, full development environment |
If you only need to compile C or C++ programs, the standalone gcc package is sufficient. If you plan to build packages from the AUR or compile software from source tarballs, install base-devel instead.
Install the gcc Package (Method 1)
Install GCC as a standalone package from the core repository:
sudo pacman -S gcc
This installs the C and C++ compilers (gcc and g++) along with the required runtime libraries.
Install the base-devel Metapackage (Method 2)
Install the base-devel metapackage, which includes GCC and the full set of build tools:
sudo pacman -S base-devel
The base-devel metapackage pulls in make, autoconf, automake, patch, pkgconf, fakeroot, and other tools needed for makepkg. This is the recommended method if you use an AUR helper like Yay or Paru, since AUR packages require base-devel to build.
Verify GCC Installation on Arch Linux
Confirm GCC is installed and check which version is active on your system.
Check the GCC version:
gcc --version
Expected output:
gcc (GCC) 15.2.1 20260209 Copyright (C) 2025 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Check the G++ (C++ compiler) version:
g++ --version
Expected output:
g++ (GCC) 15.2.1 20260209 Copyright (C) 2025 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The which command confirms the binary location:
which gcc
Expected output:
/usr/bin/gcc
Compile Test Programs with GCC on Arch Linux
Test the compiler by building and running simple C and C++ programs. This confirms that GCC, the linker, and the standard libraries are all working correctly.
Compile a C Program
Create a test file called hello.c:
#include <stdio.h>
int main() {
printf("Hello, World from GCC on Arch Linux!\n");
return 0;
}
Compile and run it:
gcc hello.c -o hello
./hello
Expected output:
Hello, World from GCC on Arch Linux!
Compile a C++ Program
Create a test file called hello.cpp:
#include <iostream>
int main() {
std::cout << "Hello, World from G++ on Arch Linux!" << std::endl;
return 0;
}
Compile and run it with g++:
g++ hello.cpp -o hello_cpp
./hello_cpp
Expected output:
Hello, World from G++ on Arch Linux!
Install Additional GCC Frontends on Arch Linux
GCC supports languages beyond C and C++ through additional frontend packages. Each frontend provides the compiler for its respective language and shares the same GCC backend and optimization infrastructure.
| Package | Language | Install Command |
|---|---|---|
gcc-fortran | Fortran | sudo pacman -S gcc-fortran |
gcc-ada | Ada (GNAT) | sudo pacman -S gcc-ada |
gcc-go | Go | sudo pacman -S gcc-go |
gcc-d | D | sudo pacman -S gcc-d |
gcc-objc | Objective-C | sudo pacman -S gcc-objc |
gcc-rust | Rust | sudo pacman -S gcc-rust |
gcc-m2 | Modula-2 | sudo pacman -S gcc-m2 |
gcc-gcobol | COBOL | sudo pacman -S gcc-gcobol |
Install multiple frontends in a single command by listing them together:
sudo pacman -S gcc-fortran gcc-go
For a complete reference on GCC configuration and usage on Arch Linux, see the Arch Wiki GCC page.
Troubleshoot GCC on Arch Linux
GCC Command Not Found After Installation
If you see this error after installing GCC:
bash: gcc: command not found
The shell session may not have picked up the new binary. Start a new terminal session and try again. If the error persists, search your locally installed packages to confirm GCC is present:
pacman -Qs gcc
If GCC is installed, the output includes entries like these:
local/gcc 15.2.1+r604+g0b99615a8aef-1
The GNU Compiler Collection - C and C++ frontends
local/gcc-libs 15.2.1+r604+g0b99615a8aef-1
Runtime libraries shipped by GCC
If the output does not list the gcc package, reinstall it:
sudo pacman -S gcc
Linker Cannot Find a Required Library
This linker error means a required library is missing from your system. For example:
/usr/bin/ld: cannot find -lssl: No such file or directory
Use pacman -F to find which package provides the missing library file. If this is your first time using the file search, update the file database first:
sudo pacman -Fy
pacman -F libssl.so
The output shows which package provides the missing file:
core/openssl 3.6.1-1
usr/lib/libssl.so
Install the package listed in the results. In this example, the openssl package provides libssl.so:
sudo pacman -S openssl
Missing Header File During Compilation
This error appears when a header file referenced in your code is not installed. For example:
fatal error: curl/curl.h: No such file or directory
Search for the filename and install the corresponding package:
pacman -F curl.h
The output identifies the package that provides the missing header:
core/curl 8.18.0-3
usr/include/curl/curl.h
Install the package from the results:
sudo pacman -S curl
On Arch Linux, most packages include both runtime libraries and development headers in the same package, unlike Debian-based distributions that split them into separate -dev packages.
Remove GCC from Arch Linux
If you installed GCC as a standalone package, remove it along with any unused dependencies. The -Rns flags combine removal (-R) with orphaned dependency cleanup (-s) and backup configuration file deletion (-n) for a complete uninstall:
sudo pacman -Rns gcc
If you installed the base-devel metapackage and want to remove the entire set of build tools:
sudo pacman -Rns base-devel
Removing
base-develalso removesmake,autoconf,automake, and other build tools. Only do this if you no longer need to compile software from source or build AUR packages.
Verify GCC has been removed:
gcc --version
Expected output confirming removal:
bash: gcc: command not found
Frequently Asked Questions About GCC on Arch Linux
The gcc package installs only the C and C++ compilers. The base-devel metapackage includes gcc along with autoconf, automake, make, patch, pkgconf, fakeroot, and over 20 other tools needed for building software from source and compiling AUR packages. Install base-devel if you plan to use makepkg or an AUR helper.
Use the g++ command instead of gcc. While gcc can compile C++ files with the correct flags, g++ automatically links the C++ standard library and treats source files as C++ by default. For example, run g++ program.cpp -o program to compile a C++ source file.
Common flags include -Wall to enable all warnings, -Wextra for additional warnings beyond -Wall, -O2 for standard optimization, -g to include debugging symbols for use with GDB, and -std=c17 or -std=c++20 to specify the language standard. Combine them as needed: gcc -Wall -Wextra -O2 -o program source.c.
Conclusion
You now have GCC set up on Arch Linux through the standalone gcc package or the base-devel metapackage. Compiling C and C++ code with gcc and g++, adding frontends like gcc-fortran for other languages, and using pacman -F to track down missing libraries cover the most common development tasks from single-file programs to full source builds.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="URL">link</a><blockquote>quote</blockquote>