How to Install GCC on Ubuntu

To install GCC on Ubuntu, open a terminal and run sudo apt update, followed by sudo apt install gcc g++. Ubuntu’s current developer documentation uses these packages for the default C and C++ compilers. If you also want common build tools and development headers, install build-essential instead or afterward.

Install GCC on Ubuntu with APT

The simplest method is Ubuntu’s APT package manager. The gcc package provides the release’s default GNU C compiler, while g++ provides the C++ compiler. The exact GCC version depends on your Ubuntu release, so you do not need to hard-code a version number for a normal installation.

1. Open Terminal

Press Ctrl + Alt + T on Ubuntu Desktop, or open Terminal from the application menu. On Ubuntu Server, sign in to the shell as usual.

Ubuntu Terminal open at a user shell prompt before installing GCC
An Ubuntu terminal window ready for the GCC installation commands.

2. Refresh the package index

Update APT’s package information before installing the compiler:

sudo apt update

If sudo asks for your password, type it and press Enter. Ubuntu normally does not show characters or asterisks while you type a sudo password.

3. Install the C and C++ compilers

Install Ubuntu’s default GCC packages:

sudo apt install gcc g++

Review the proposed packages and disk-space changes, then confirm the installation when APT prompts you. This matches the current Ubuntu developer guide for setting up GCC.

Ubuntu Terminal showing apt update and the sudo apt install gcc g++ command
APT refreshing package information and preparing to install GCC and G++.

Verify that GCC is installed

After APT finishes, check the compiler:

gcc --version
g++ --version
command -v gcc

The version number can differ across supported Ubuntu releases. That is expected: Ubuntu’s gcc package tracks the default compiler chosen for that release. The final command should normally print a path such as /usr/bin/gcc.

Ubuntu Terminal showing the gcc --version command and GCC version output
Use gcc --version to confirm that the compiler is available.

Compile a quick test program

You can confirm that compilation and linking work by building a tiny C program. Create hello.c with the following contents:

#include <stdio.h>

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

Then compile and run it:

gcc hello.c -o hello
./hello

You should see Hello, world!. GCC normally handles preprocessing, compilation, assembly, and linking when you invoke it this way, as described in the official GCC manual.

Ubuntu Terminal compiling hello.c with gcc and running the Hello world executable
A simple C program compiled with GCC and run successfully from the terminal.

Should you install build-essential instead?

For many development tasks, build-essential is more convenient than installing only the compilers. It is a meta-package that pulls in GCC, G++, GNU Make, development headers, and Debian package-development tools needed by many source builds.

sudo apt install build-essential

If you already installed gcc g++, installing build-essential is safe; APT will keep the existing compiler packages and add any missing dependencies. You can review the package dependencies on Ubuntu’s official package site.

Install a specific GCC version

Ubuntu repositories can contain several GCC releases at the same time, but the available versions depend on your Ubuntu release and enabled repositories. Avoid copying old lists such as “gcc-7 through gcc-10,” because those package names are no longer a reliable guide for current systems.

First, see which versioned compiler packages your configured repositories offer:

apt-cache search '^gcc-[0-9]+$'

If the version you need appears, install the matching C and C++ packages. For example, when version 14 is available:

sudo apt install gcc-14 g++-14
gcc-14 --version

Replace 14 with the version present in your repository. You can keep multiple versions installed and invoke a specific compiler directly, such as gcc-14, without changing the system-wide gcc command. Ubuntu also maintains an official GCC availability reference, although your own APT results are the best check for the repositories actually configured on your machine.

Common installation problems

  • “Unable to locate package”: run sudo apt update and confirm that your Ubuntu release is still supported and its normal repositories are enabled.
  • gcc: command not found after installation: run command -v gcc and dpkg -l gcc to confirm the package is installed.
  • A project reports missing headers or make: install build-essential, then install any project-specific -dev libraries named by the build error.

For a standard Ubuntu C/C++ setup, sudo apt install gcc g++ is the direct route; build-essential is the better choice when you also need the usual build toolchain.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.