How to Install C – Learn to Install GCC Compiler for Ubuntu
How to Install C Programming Language?
Still stuck with the same problem of how to install C? You cannot install a programming language. Since C is a programming language, you directly start writing programs in it.
Then what do you install? The answer is- you need to install a Compiler, i.e. GCC Compiler, to compile and run your programs using it. This compiler recognizes the language by its syntax.
Stay updated with latest technology trends
Join DataFlair on Telegram!!
Steps to Install C Language
In this installation tutorial, we will help you to write and compile your own programs in the C programming language using terminal for Linux Operating System.
1. Environment for C programming
The terminal command prompt is pre-installed in your LINUX operating system. Our task now is to install the GCC compiler using terminal to execute the C programs.
Check the 8 Crucial Features of C Language & find the Reason behind its Popularity
2. How to install GCC compiler using terminal in Linux?
You can find the terminal icon on your Desktop screen. If not, you can find it through the search menu. A shortcut to open terminal is: Press Ctrl + Alt + T.
Open terminal so that we can proceed with the further steps to install the GCC Compiler.
The main command for installing the GCC compiler using terminal on Ubuntu is:
sudo apt install GCC
Here, GCC is the C compiler.
If you do not have permission to install the GCC compiler, this message would be displayed where you are required to enter the admin password to get the permission granted:
If you have permission, then the installation process will proceed as follows:
Type ‘y’ when the command prompt asks “Do you want to continue?” and then press Enter.
Thereafter, your installation will begin
3. How to check the installed compiler version?
- You can find the terminal icon on your Desktop screen or on the search menu. A shortcut to open terminal is: Press Ctrl + Alt + T simultaneously.
- Now the terminal will open.
- The ‘gcc’ command will help you throughout your coding journey. It is a very important command that comes pre-installed on your latest Ubuntu version.
- Write the following command to know the version of the GCC compiler that you installed
GCC — version
￼After pressing enter, the version of the terminal software would be displayed.
This version is 7.4.0
If you don’t see such a message on your display screen, then it probably means that you haven’t successfully installed the GCC compiler.
4. How to create a C program?
In order to create a C program, use the ‘touch’ command and give the name of the file with .c extension
But before that, you need to choose the directory you are working on.
Most of the programmers generally prefer to work on the Desktop folder as it proves to be quite convenient to write, modify and run your programs instantly.
In order to locate your files on the Desktop folder and to change the reference of the current directory to Desktop, use this command:
Key takeaway: Commands are case sensitive
The command for creating a program in C is:
Now, a file has been created in our Desktop folder called program.c
Open this file and write a basic code – “Hello World!”
5. How to compile and run a C program?
Now that we have created a C program called program.c, it is now time to compile it and run it in terminal.
To compile the code, we use the GCC command:
GCC program.c -o program
Here, the ‘gcc’ command is followed by the file name with .c extension and ‘-o’ and the name of the executable file, which is, ‘program’ in this case.
Key takeaway: The executable file name can be different from the source file name
In order to run the program, use the command
Here, the period symbol ‘.’ followed by a backslash is followed by the name of the executable file, that is, ‘program’ in this case
The program output would be:
In this way, you can install the GCC compiler using terminal when working on the LINUX OS. We inferred that it is pretty easy to install the GCC compiler in LINUX as it requires only one command. Thereafter, we saw how to check the version of the installed compiler. Then, we saw how to create a program in C with the help of certain commands. Finally, we learned how to compile and run C programs using terminal.
We hope you found this tutorial helpful for installing the GCC compiler using terminal for LINUX!
If you have any queries regarding the installation process or if you’re finding any difficulties to install C in your system feel free to leave a comment below.
Don’t forget to check Applications of C Programming That Will Make You Fall In Love With C