How to Install GCC on Ubuntu and Linux — Step-by-Step (2026)

Linux is the natural home for C programming — and installing GCC takes just one command. On most Linux distributions GCC is either already installed or a single package away. This guide covers Ubuntu/Debian, Fedora/RHEL, and Arch, then shows you how to compile and run your first program.

On a shared machine where you cannot install packages? You can still write and run C in your browser — see our guide to online C compilers. No installation needed.

Step 1 — Check If GCC Is Already Installed

Many Linux systems ship with GCC. Open a terminal and check:

gcc --version

If you see a version number like gcc (Ubuntu 14.x) 14.x.x, you already have it — skip to compiling your first program below. If you see command not found, install it using the steps for your distribution.

Step 2 — Install GCC for Your Distribution

Ubuntu / Debian / Linux Mint / Pop!_OS

Install the build-essential package, which includes GCC, make, and other tools you will need:

sudo apt update
sudo apt install build-essential

Fedora / RHEL / CentOS / Rocky Linux

sudo dnf install gcc

Or, to install the full development tool group:

sudo dnf groupinstall "Development Tools"

Arch Linux / Manjaro

sudo pacman -S base-devel

openSUSE

sudo zypper install gcc

Step 3 — Verify the Installation

gcc --version

You should now see the installed version, for example:

gcc (Ubuntu 14.2.0) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.

Step 4 — Compile and Run Your First Program

Create a file called hello.c using any text editor (or nano hello.c in the terminal):

#include <stdio.h>

int main(void) {
    printf("Hello from Linux!\n");
    return 0;
}

Compile and run it:

gcc hello.c -o hello
./hello

Output:

Hello from Linux!

The ./ before hello is required — it tells the shell to run the program from the current directory. For learning, always compile with warnings enabled:

gcc -Wall -Wextra -std=c17 hello.c -o hello

No Linux Machine? Practise on a Cloud Server

If you are on Windows or macOS but want to learn C in a real Linux environment — the same environment used on most servers — you do not need to dual-boot or wipe your machine. You can spin up a small Linux server (a “droplet”) in the cloud in about a minute.

DigitalOcean gives new users $200 in free credit for 60 days — more than enough to practise C on a real Ubuntu server at no cost. Create a droplet, connect over SSH, run the apt install build-essential command above, and you have a clean Linux C development environment to experiment with. It is also a great way to learn the command-line skills that professional C development relies on.

The DigitalOcean link is a referral link — signing up through it supports this site, and you still get the full $200 credit.

Common Issues

Problem Fix
gcc: command not found after install Open a new terminal, or run hash -r to refresh the shell’s command cache
E: Unable to locate package build-essential Run sudo apt update first, then install again
Permission denied running ./hello Make it executable: chmod +x hello
sudo: command not found You are likely root already — drop the sudo prefix
Want a newer GCC than your distro ships On Ubuntu, add the ubuntu-toolchain-r/test PPA, or build from source

What’s Next

GCC is installed. For a full editor with code completion and a visual debugger, set up VS Code for C programming — it works great on Linux. To understand which compiler you are actually using and how GCC compares to Clang, see our guide to the best C compilers.

Then start writing real programs — browse our full list of C programs with examples.


The DigitalOcean link above is a referral link. As an Amazon Associate we also earn from qualifying book purchases.

Recommended Book

The best book to learn C once your environment is ready — The C Programming Language by Kernighan and Ritchie (K&R). For more options, see our guide to the best C programming books.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>