Where to install gcc in linux?
GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The GCC is an open-source collection of compilers and libraries.
Let’s start with the steps to install the GCC on Linux.
To install the GCC open the terminal on Linux.
The terminal takes the input from the user in the form of commands and displays the output on the screen. Hence we have to pass some commands to install the GCC.
Follow the commands step by step to install the GCC.
Command 1: The very first step is to update the packages. This command is used to download package information from all configured sources and to get the info of the updated versions of the packages.
Note: In the first command it will ask for your password, make sure to enter the password correctly.
Command 2: Now we have to install the build-essential packages, which is also known as a meta-package, it contains the GCC compiler all the other essentials used to compile the software written in C and C++ language.
It will take some time to install all the essential packages.
Command 3: After the second command it will install GCC on your Linux, to verify it is installed correctly, check the version of the GCC.
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.
The build-essential package has its dependencies as gcc, g++ (GCC, but for C++), make and dpkg-dev (to build .deb packages).
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:
Once the GCC package is installed, you can verify that it is working using the gcc --version command.
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:
The build-essential package installs several development tools like:
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:
- sudo apt install GCC.
- GCC — version.
- cd Desktop.
- Key takeaway: Commands are case sensitive.
- touch program.c.
- GCC program.c -o program.
- Key takeaway: The executable file name can be different from the source file name.
- ./program.
In this section, you will to create a simple C program on Linux using a pre-installed text editor.
There are many Linux terminal commands to create a new file like using the touch, > (redirect operator), cat, echo commands, or terminal editors like vi, vim, or nano. We are using the touch command in this tutorial in the terminal to create an empty C program file. Before creating a new file, you can also change the directory of the terminal to any desired location in your system. We have chosen the Desktop directory in this tutorial. You can change to Desktop directory using cd Desktop (change directory to Desktop) command or you can choose any directory of your choice, just pass the location address of the directory after the cd command. You have to make sure that the C program file is compiled in the same directory as where the C program file is present.
Let's see this in action in Ubuntu 20.04 OS.
Step 1: touch hello.c command in the terminal will create an empty hello.c C program file in the desktop directory.
Step 2: Open the hello.c file in the in-built text editor of Linux (or you can use any editor of your choices like Sublime Text or Visual Studio Code) and type the Hello World C program in the editor as given below.
You can also check and run this program here. (IDE by InterviewBit)
OUTPUT:
Hello, World!
More Questions
- What is a wpa passphrase?
- What is pymysql in python?
- What is uee in education?
- What is bou and cou in bbps?
- What should you not miss in san antonio?
- What does qwb mean?
- What is akong music bank?
- What is amazon free tier?
- What is the best of lexington 2020?
- There are some important metrics for individual sales reps.