Introduction
If you are reading this blog, then it means you have used a computer or smartphone in your life, so have you ever wondered how they respond to our command and communicate within themselves and show us the required result or perform the operation necessary?
If you are a newbie or beginner in the world of programming, then you must know that computers cannot understand the languages as we do. They only understand the machine language, i.e., binary language( only 0 and 1). The request we make is converted into machine language and then sent and understood by the computer.
And Compiler help in translating your request into machine language to get you the required result. We will learn more about compilers and how to install a C++ compiler in Ubuntu while moving further with the blog. So without wasting any further time, let's get on with our topic.
Also, see Literals in C.Fibonacci Series in C++ and,Lexical Analysis in Compiler Design
Install g++ on Ubuntu
A compiler can be understood as a program that converts your input into machine language to get the required result.
In this blog section, we will install g++ is, referred to as a C++ compiler command that can be utilized to create an executable file through linking, pre-processing, compilation, and assembling source code. With the help of g++ commands, we can stop the process according to our requirements. You need to follow certain steps to install g++, which are explained below:
- Open terminal in Ubuntu “Ctrl+alt+T” . OR you can search it manually ib the application’s bar

2. Now update all the repositories by running the following command in the terminal.
$ sudo apt update
3. Now install g++ by running the following command in the terminal:
$ sudo apt install g++
4. At last, verify that g++ is installed on your system or not by running the following command in the terminal. If g++ is present, it will show the latest version of it. Otherwise, it will not show anything. Then you can install g++ first.
$ g++ --version
Compile a C++ script with g++
In this blog section, we will create a sample script and compile it using g++ in the compiler. We will use a nano editor to create a “samplefile.cpp” by running the following script.
$ nano samplefile.cpp
Now you can add the code given below in your file and save by pressing "CTRL + O"
#include<stdio.h>
int main()
{
printf ("This is a test file\n");
return 0;
}
The screen will look like this:

Before running, we have to convert this file into an executable file by running the following script in your terminal:
$ g++ samplefile.cpp -o samplefile
Now, you can run your file in the terminal by executing the following command:
$ ./samplefile
The output will be as follows:

Also Read - C++ Interview Questions And Abstract Data Types in C++