Skip to main content
How To

How to Install GCC on Ubuntu

The GNU C Compiler (gcc) is required for compiling C and C++ code. You can install it directly or with other dev tools with build-essential package.

Pratham Patel

The term GCC refers to the C (and C++) compiler offered by the GNU toolchain of compilers. It abbreviates to GNU C Compiler.

If you looked at a few C or C++ tutorials, you might have noticed that they use the gcc compiler to compile the code.

GCC is available in the Ubuntu repositories as the gcc package itself, but if you are going to compile a whole project, it is best to install the build-essential package.

sudo apt install build-essential

The build-essential package has its dependencies as gcc, g++ (GCC, but for C++), make and dpkg-dev (to build .deb packages).

Install only GCC

The GNU C Compiler, commonly referred to as GCC, is an essential piece of open source software development. Hence, it is available in the Ubuntu repositories as the gcc package.

The GNU C Compiler can be installed using the following command:

sudo apt install gcc
Install gcc on Ubuntu

Once the GCC package is installed, you can verify that it is working using the gcc --version command.

$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 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.

Install GCC along with useful tools via build-essential

When you install the GNU C Compiler using the gcc package, only the GNU C Compiler is installed.

I assume you want to install GCC because you are working on a software project written in the C programming language. In that case, I advise you to install the build-essential pacakge. It is a meta package of sorts.

A meta package is a package that does not have anything of its own but rather acts as a package to install a collection of related packages.

The build-essential meta package can be easily installed with the apt package manager:

sudo apt install build-essential
Install Build Essential package in Ubuntu

The build-essential package installs several development tools like:

  • libc6-dev: The header files for GNU C Library (glibc)
  • gcc: The GNU C Compiler
  • g++: The GNU C++ Compiler
  • make: Build tool for a medium-large software package
  • dpkg-dev: Build a package in .deb packaging format (used by Debian and Ubuntu)

These tools come in handy when you are working on a codebase that is medium to large.

Once the build-essential package is installed, and you can verify the version of the GNU C Compiler with the following command:

gcc --version

Conclusion

The GNU C Compiler is available in the Ubuntu repositories. That makes the installation very easy. Canonical also provides the build-essential package that installs GCC and other tools that help compile medium to large software projects.

Pratham Patel