How to install a C compiler on Linux



Whether you code in C or build a Linux program from source, you will need to install a C compiler. The two main ones on Linux are the venerable GCC and the newer Clang.

Here is how you can install them both on your machine.

Install GCC on Linux

GCC, or GNU Compiler Collection, has been around since the 1980s, before Linux itself. Not only does it compile C programs, but also supports C ++, Objective-C, Objective-C ++, Fortran, ADA, and Go. Many open source projects still depend on it, including the Linux kernel.

To install GCC with the required C libraries on Debian and Ubuntu, install the build-essential wrap:

sudo apt install build-essential

On Fedora and other RPM-based distributions:

sudo dnf install gcc

And on Arch Linux:

sudo pacman -S gcc

On any other distribution you can usually search for “GCC” and you will find a package for your system. This also applies to Clang.

To compile a simple C program, like the famous “Hello, World!”, Just go to the directory where you saved it and run the following command:

gcc hello.c

…or Hello C is the name of your program.

GCC release under Linux

If the program is correct, GCC will display the compiled file as August in the current directory. To run it, type:


Related: How to print “Hello, World!” in the 20 most popular programming languages

Install Clang on Linux

The most recent on the block is the Clang compiler, developed on the front of the LLVM compiler by Apple, ARM, Sony, AMD and others. Apple uses it as a compiler for its Xcode development environment for macOS.

Clang aims for compatibility with GCC, while increasing performance. It’s popular because it’s licensed under the Apache 2.0 license, which doesn’t require developers to release their source code if they make any changes.

You can install Clang using your package manager. On Debian and Ubuntu, simply install the noise wrap:

sudo apt install clang

On Fedora / CentOS:

sudo dnf install clang

To install Clang on Arch-based distributions:

sudo pacman -S clang

Compilation works the same as with GCC:

clang hello.c

Clang release on Linux

Related: Basic Programming Principles Every Programmer Should Know

You can now compile C programs in Linux

Whether you are just learning C or are an experienced C programmer, you can easily install two major C compilers for Linux: GCC and Clang.

If you want to explore C programming, here are some more language tips that will give you a head start.


5 C programming tips you need to learn to get started

The C programming language has a tough reputation. But if you master it, you can program everything, as these tips show.

Read more

About the Author


Leave A Reply

Your email address will not be published.