How to set up a development environment for GCC on Ubuntu

The GNU Compiler Collection (GCC) is a set of compilers for programming languages, including C, C++, Assembly, and many more. It is the de facto standard in Linux environments and is used to compile both the GNU toolchain and the Linux kernel.

This guide shows how to install GCC and related tooling, including a build system and debuggers, on Ubuntu Desktop.

Installing GCC

The GCC toolchain, including past versions and cross-compilers for different architectures, is included in the Ubuntu package repository. The gcc package provides the default version of GCC for your platform. gcc runs the C compiler and g++ runs the C++ compiler.

  1. Install GCC compilers for C and C++:

    sudo apt install gcc g++
    
  2. Confirm the version of the installed compiler:

    dev@ubuntu:~$
    gcc --version
    gcc (Ubuntu 14.2.0-4ubuntu2) 14.2.0
    Copyright (C) 2024 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.
    

Note

You may see a different version number from the one listed here. That is not a problem.

Installing editing and debugging tools

Text editors and Language Server Protocol (LSP) servers

Some developers prefer advanced text editors such as Vim, Codium, or Visual Studio Code with Language Server Protocol (LSP) plug-ins for a lightweight and streamlined development experience.

Vim with LSP

A mode-driven text editor with powerful editing features. Combined with an LSP, such as ccls, it offers code completion, linting, navigation, and more.

Install with:

sudo apt install -y vim ccls

Refer to the ccls editor configuration instructions for Vim LSP setup.

Codium

The freely-licensed binary distribution of Microsoft’s Visual Studio Code. It includes extensive C/C++ support out of the box, and numerous extensions available from the open-source Open VSX registry provide support for additional functionality for coding with C. For example, the all-in-one C/C++ Extension Pack.

Install with:

sudo snap install codium --classic
Visual Studio Code

The popular editor from Microsoft with an extensive range of extensions for C/C++ development, including the C/C++ extension also from Microsoft.

Install with:

sudo snap install code --classic

Integrated development environments

Other developers enjoy the full support offered by Integrated Development Environments (IDEs). Several IDEs available in the Ubuntu .deb and snap repositories are excellent choices for developing C and C++ applications:

Code::Blocks

A dedicated and easy-to-use C, C+, and Fortran IDE that is often featured in C/C++ programming tutorials.

Install with:

sudo apt install -y codeblocks
Eclipse CDT™ C/C++ Development Tools

A C/C++ IDE based on the Eclipse IDE platform.

Install with:

sudo snap install eclipse --classic

From within Eclipse, install CDT by going to Help ‣ Install New Software… and use https://download.eclipse.org/tools/cdt/releases/latest/ for the Work with: field.

Apache NetBeans

The NetBeans C/C++ Development Pack adds support for C/C++ to NetBeans.

Install with:

sudo apt install default-jre
sudo snap install netbeans --classic

From within NetBeans, install the C/C++ Pack by going to Tools ‣ Plugins ‣ Available Plugins ‣ Install.

Debuggers, profilers, and other tooling

The standard debugger developed for GCC is the GNU Debugger (GDB). Other tools, such as gprof (part of binutils) and Valgrind provide support for profiling and advanced dynamic analysis.

Install with:

sudo apt install -y gdb valgrind

(The binutils package is installed automatically with gcc.)

See the GDB manual and Valgrind documentation for more information about how to troubleshoot your programs.

Build systems

The standard for GNU software is GNU Make. For larger projects and a more modern experience, consider CMake.

Install with:

sudo apt install -y make cmake

See the GNU Make manual and the CMake tutorial for more information about these build systems.

What next

See the tutorial introducing the use of GCC and related tooling: Develop with GCC on Ubuntu.