Whether you're coding in C or building a Linux program from source code, you'll need to install a C compiler. The two most important on Linux are the venerable GCC and the newer Clang.
This is how you can install both on your computer.
Install GCC on Linux
GCC, or the GNU Compiler Collection, has existed since the 1980s and is older than Linux itself. It not only compiles C programs, but also processes C ++, Objective-C, Objective-C ++, Fortran, ADA and Go. Many open source projects still rely on it, including the Linux kernel.
To install GCC along with the required C libraries on Debian and Ubuntu, install the essential to construction Package:
sudo apt install build-essential
On Fedora and other RPM-based distributions:
sudo dnf install gcc
And on Arch Linux:
sudo pacman -S gcc
For any other distribution, you can usually search for "GCC" and find a package for your system. This also applies to clang.
To create a simple C program like the famous "Hello, World!" To compile, just go to the directory where you saved it and run the following command:
…Where Hello c is the name of your program.
If the program is correct, GCC will output the compiled file as a a.out in the current directory. Enter the following to run it:
Install Clang on Linux
The newer kid on the block is the Clang compiler, which was developed by Apple, ARM, Sony, AMD, and others as the front line to the LLVM compiler. Apple uses it as a compiler for its Xcode development environment for macOS.
Clang aims to be compatible with GCC while increasing performance. It's popular because it's licensed under the Apache 2.0 license that doesn't require developers to release their source code when they make changes.
You can install Clang using your package manager. On Debian and Ubuntu, just install the ring Package:
sudo apt install clang
On Fedora / CentOS:
sudo dnf install clang
To install Clang on Arch-based distributions:
sudo pacman -S clang
Compiling works the same way as with GCC:
You can now compile C programs on Linux
Whether you are studying C or are an experienced C programmer, you can easily install two important C compilers for Linux – GCC and Clang.
If you want to get to know 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 bad reputation. But once you get it under control, anything can be programmed, as these tips show.
About the author
(59 articles published)
David is a freelance writer living in the Pacific Northwest but originally from the Bay Area. He has been passionate about technology since childhood. David's interests include reading, watching quality TV shows and movies, retro games, and collecting records.
By David Delony
Subscribe to our newsletter
Subscribe to our newsletter for tech tips, reviews, free e-books, and exclusive offers!
Click here to subscribe