1

How to Install a C Compiler on Linux

 2 years ago
source link: https://www.makeuseof.com/how-to-install-c-compiler-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Install a C Compiler on Linux

By David Delony

Published 16 hours ago

Get started with C programming by installing an open-source C compiler on your Linux machine.

Whether you're coding in C or building a Linux program from the source, you'll have to install a C compiler. The two major ones on Linux are the venerable GCC and the newer Clang.

Here's how you can install them both on your machine.

Installing GCC on Linux

GCC, or the GNU Compiler Collection, has been around since the 1980s, predating Linux itself. Not only does it compile C programs, but also handles C++, Objective-C, Objective-C++, Fortran, ADA, and Go. A lot of 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 build-essential package:

sudo apt install build-essential

On Fedora and other RPM-based distros:

sudo dnf install gcc

And on Arch Linux:

sudo pacman -S gcc

On any other distribution, you can usually search for "GCC" and you'll find a package for your system. This goes for Clang as well.

To compile a simple C program, such as the famous "Hello, World!", just go to the directory where you saved it and run the following command:

gcc hello.c

...where hello.c is the name of your program.

GCC output in Linux

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

./a.out

Related: How to Print "Hello, World!" in the 20 Most Popular Programming Languages

Installing Clang on Linux

The newer kid on the block is the Clang compiler, developed as a front to the LLVM compiler by Apple, ARM, Sony, AMD, and others. Apple uses it as the 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 modifications.

You can install Clang using your package manager. On Debian and Ubuntu, just install the clang 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 as with GCC:

clang hello.c
Clang output in Linux

Related: Basic Programming Principles Every Programmer Should Know

Now You Can Compile C Programs in Linux

Whether you're 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 tips on the language that will give you a headstart.

About The Author

6053bdfb33ee5-David_Delony_Headshot.jpg?fit=crop&w=100&h=100

David Delony (59 Articles Published)

David is a freelance writer based in the Pacific Northwest, but originally hailing from the Bay Area. He has been a technology enthusiast since childhood. David's interests include reading, watching quality TV shows and movies, retro gaming, and record collecting.

More From David Delony

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK